Skip to content

Instantly share code, notes, and snippets.

@cbhyphen
Last active April 6, 2016 16:34
Show Gist options
  • Select an option

  • Save cbhyphen/01352af75ec759fc7798e93059836332 to your computer and use it in GitHub Desktop.

Select an option

Save cbhyphen/01352af75ec759fc7798e93059836332 to your computer and use it in GitHub Desktop.
pyschedelic-turtle
#!/usr/bin/python
import turtle, math, colorsys
def draw_tunnel(some_turtle):
distance = 50.0
n = 200
for i in range(n):
step = 0.09 * distance
diag1 = math.sqrt((distance + step)**2 + step**2)
angle1 = math.degrees(math.atan(step/(step+distance)))
diag2 = math.sqrt((2*step)**2 + distance**2)
angle2 = math.degrees(math.atan(2*step/distance))
color = colorsys.hsv_to_rgb((1.0*i)/n, 1.0, 1.0)
some_turtle.color(color)
some_turtle.forward(distance)
some_turtle.right(90)
some_turtle.forward(distance)
some_turtle.right(90 + angle1)
some_turtle.forward(diag1)
some_turtle.right(90 - angle1 + angle2)
some_turtle.forward(diag2)
some_turtle.right(90)
distance = diag2
if __name__ == "__main__":
window = turtle.Screen()
window.bgcolor("black")
timmy = turtle.Turtle()
timmy.shape("turtle")
timmy.color("green")
timmy.speed(0)
draw_tunnel(timmy)
window.exitonclick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment