Spiral problem

[edit: attached Customer Service tag, but can’t change that…]

I have this Cartesian Coordinates. At 0,0 I place a square, then I go south 1 and place a square, go west 1, place a square, go north 1, go east 1, place a square, go south etc.

In every step it must be considered if the neighbor (for direction east look south, for direction south look west, for direction west look north, for direction north look east) square is empty. If so, continu that path, place a pixel. Loop.

For the first steps the algorithm looks like:
dim x,y as integer
dim steps as integer = 5000

while true
//placeCube draws the cube or pixel
placeCube(x,y)
//go south 1
y=y-1
placeCube(x,y)
x=x-1
placeCube(x,y)
y=y+1
placeCube(x,y)
x=x+1
PlaceCube(x,y)
wend

The thing I try to put in the algorithm is that when encountered a neighbor, place a cube and then change course as directed. Help very much appreciated…

You might want to move this to the general channel. I suspect you won’t get too many answers in Customer Service.

Done…

Add a direction component to your algorithm say

1 = South
2 = West
3 = North
4 = East

Then in your loop you would test the next cell based on which direction you’re moving

While True
Select Case Direction
Case 1 ’ Keep moving south until I can move West
Placecube
If cell(x -1, y + 1) = True Then ’ cube there
y = y + 1 ’ keep moving south
Else
x = x - 1
Direction = 2
End If

etc.

OK, thanks Wayne. I’ll look into that.

I believe something like this should work:

Dim i as integer
Dim x as integer
**loop ___ times
for x = 0 to i
placeCube
moveToNextBlock
next x
changeDirection
for x = 0 to i
PlaceCube
moveToNextBlock
next x
changeDirection
i = i + 1
**end loop

This assumes that the grid is blank already, as it doesn’t actually check for an occupied block, it just iterates over 2 sides of the same # of blocks, then increases the # by 1 for the next 2 sides.