Is there any equation to figure out what square is next on a spiral like path? I have a grid, with an object in the center, and want to be able to look at the surrounding squares in a repeat...until loop to figure out which is the next open square (like this)
where "x" is the center object (which I need to be a variable size), and the squares checked are in the order of the numbers, continuing forever unitl a square that is not occupied crops up. Is there a way to do this? I have only come up with a formula (that only works sometimes) that looks for the object if a square is ocuppied and moves according to if it is there or not.
I am using a two dimensional array to store which squares are free and which are occupied.
0 1 2 3 4 5 ------------------------------- 1 | 19 | 18 | 17 | 16 | 15 | ------------------------------ 2 | 20 | 05 | 04 | 03 | 14 | ------------------------------ 3 | 21 | 06 | XX | 02 | 13 | ---------| XX |--------------- 4 | 22 | 07 | XX | 01 | 12 | ------------------------------ 5 | 23 | 08 | 09 | 10 | 11 | ------------------------------
where "x" is the center object (which I need to be a variable size), and the squares checked are in the order of the numbers, continuing forever unitl a square that is not occupied crops up. Is there a way to do this? I have only come up with a formula (that only works sometimes) that looks for the object if a square is ocuppied and moves according to if it is there or not.
I am using a two dimensional array to store which squares are free and which are occupied.
