LoginSignup
2
2

More than 5 years have passed since last update.

値をぐるぐる回したいときや、描画をトーラスにしたいときなどに使う式

Last updated at Posted at 2013-11-03

だいたいこんな感じにかけばいい

x = (x+width)%width;
y = (y+height)%height;

普通にxをwidthで割ってもいいのだけれど、width足してあげるとxがマイナスの時もいい感じになる。
ただx < -widthだと意味が無い。でもそういう時あるかしら?あるかもしれませんね。
さらにオーバーフローとかには注意しないといけない時もあるかもしれない。結局心配な時はif文で丁寧にやるのが良いかもしれない

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2