Skip to content

Instantly share code, notes, and snippets.

@rabssm
Last active April 28, 2018 11:26
Show Gist options
  • Save rabssm/0d05d987e19d20bf9ec192793f08d70b to your computer and use it in GitHub Desktop.
Save rabssm/0d05d987e19d20bf9ec192793f08d70b to your computer and use it in GitHub Desktop.
Generate a spiral pattern, moving outwards from the centre position (0,0). Python code.
# Generate a spiral pattern, moving outwards from the centre position (0,0)
# The size parameter sets the size of the spiral "shell"
SIZE = 5
x, y = 0, 0
dx, dy = 0, -1
for i in range(SIZE**2):
if (x == y) or (x < 0 and x == -y) or (x > 0 and x == 1-y):
dx, dy = -dy, dx
print "Position:", (x, y)
x, y = x+dx, y+dy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment