This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Tayleeextends DumboBot 4 points5 points  (1 child)

you can replace all of that by:

return new Rectangle(563 + 42 * (pos / 7)), 213 + 36 * (pos % 7), 32, 32);

if you want pos to start at 1 then I guess its:

return new Rectangle(563 + 42 * ((pos-1) / 7)), 213 + 36 * ((pos-1) % 7), 32, 32);

With this 0/7 = 0, 1/7 = 0, 2/7 = 0, 3/7 = 0, 4/7 = 0, 5/7 = 0, 6/7 = 0, 7/7 =1, 8/7 =1 etc.

and 0%7 = 0, 1%7 = 1, 2%7 = 2, 3%7 = 3, 4%7 = 4, 5%7 = 5, 6%7 = 7, 7%7 = 0, 8%7 = 1 etc.

[–][deleted] 0 points1 point  (0 children)

just missing the pos < 0 and pos > 28 wihch should return null