Skip to content

Instantly share code, notes, and snippets.

@rpalo
Created December 11, 2018 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpalo/3744a2a0950f08ccfb79e57b05bdd38a to your computer and use it in GitHub Desktop.
Save rpalo/3744a2a0950f08ccfb79e57b05bdd38a to your computer and use it in GitHub Desktop.
import turtle
window = turtle.Screen()
euler = turtle.Turtle() # A good mathy name for our turtle
euler.shape("turtle")
current = 0 # Here's how we know where we are
seen = set() # Here's where we'll keep track of where we've been
# Step increases by 1 each time
for step_size in range(1, 100):
backwards = current - step_size
# Step backwards if its positive and we've never been there before
if backwards > 0 and backwards not in seen:
euler.setheading(90) # 90 degrees is pointing straight up
euler.circle(step_size/2, 180) # 180 degrees means "draw a semicircle"
current = backwards
seen.add(current)
# Otherwise, go forwards
else:
euler.setheading(270) # 270 degrees is straight down
euler.circle(step_size/2, 180)
current += step_size
seen.add(current)
turtle.done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment