Algorithm for rectilinear spiral motion (Page 1) ● SmileBASIC Source Forums

Register

# Algorithm for rectilinear spiral motion

• #1 ✎ 275 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Can't wrap my head around this one. I'm trying to get an algorithm to read/write from/on a set of data in a spiraling, rectilinear manner. Not complicated, really. Let me picture it for you: 'Consider a 3x3 gridspace: '000 '000 '000 'Begin algorithm in center '000 '010 '000 'Algorithm proceeds in spiral fashion '010 '010 '000 '... '011 '010 '000 '... '011 '011 '000 '... '011 '011 '001 '... '011 '011 '011 '... '011 '011 '111 '... 'etc. Now, when the 3x3 gridspace becomes filled, the algorithm may be pressed to continue, building upon itself with layers. I'm trying to get something like this that can continue building for n-steps. What's the best way to do this? The algorithm isn't allowed to check gridspace for its position or the states of other elements surrounding it. It's basically a snail that wants to run around in circles for n-number of paces and not touch its trail, but it can't detect its trail and its blind. However, it can remember how many paces it traveled and has a basic grasp of mathematics and SB. Posted Edited by MZ952
• #2 ✎ 1785 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Does it matter where the start of each "circle" is? Posted
• #3 ✎ 275 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Each "circle" starts one unit above where the last one ended, though, if it's any simpler starting somewhere else, it's not too big a deal Posted
• #4 ✎ 1785 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself HALF = SIZE DIV 2 PRINT HALF, HALF FOR J=1 TO HALF FOR I=-(J-1) TO J PRINT HALF+I,HALF-J NEXT FOR I=-(J-1) TO J PRINT HALF+J,HALF+I NEXT FOR I=J-1 TO -J STEP -1 PRINT HALF+I,HALF+J NEXT FOR I=-J-1 TO -J STEP -1 PRINT HALF-J,HALF+I NEXT NEXT Posted
• #5 ✎ 275 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies I may not have described this well enough, so I drew a picture hopefully explaining this a little better than the text example from earlier. Each unit square represents a "step," and the algorithm is due to run only a given number of steps in the clockwise spiraling direction I tried to outline there^ Each move is counted as a step, including the start at the origin. It starts at the origin and moves up one step where it then continues to the right, down, left, up, turning clockwise about itself. When it can no longer turn about itself without reaching its starting position, it moves up one unit and proceeds. It proceeds for as many steps as it is given, ceasing anywhere it runs out of available steps. Posted Edited by MZ952