Last active
April 28, 2018 11:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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