Advertisement
here2share

# t_Spectral_Wheel.py

Dec 30th, 2020
1,381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. # t_Spectral_Wheel.py
  2.  
  3. from turtle import Screen, Turtle
  4. from colorsys import hsv_to_rgb
  5.  
  6. RADIUS = 250
  7. NUMBER_OF_WEDGES = 25
  8. SLICE_ANGLE = 360.0 / NUMBER_OF_WEDGES
  9.  
  10. screen = Screen()
  11. screen.tracer(False)
  12.  
  13. # create a pie wedge-shaped cursor
  14. turtle = Turtle(visible=False)
  15. turtle.begin_poly()
  16. turtle.sety(turtle.ycor() - RADIUS)
  17. turtle.circle(RADIUS, extent=SLICE_ANGLE)
  18. turtle.home()
  19. turtle.end_poly()
  20.  
  21. screen.register_shape("wedge", turtle.get_poly())
  22.  
  23. # create a turtle for each wedge in the pie
  24. turtles = []
  25.  
  26. for hue in range(NUMBER_OF_WEDGES):
  27.     turtle = Turtle("wedge")
  28.     turtle.color(hsv_to_rgb(hue*1.0 / NUMBER_OF_WEDGES, 1.0, 1.0))
  29.     turtle.setheading(hue * SLICE_ANGLE)
  30.  
  31.     turtles.append(turtle)
  32.  
  33. def draw_circle():
  34.  
  35.     # have each turtle take on the color of its neighbor
  36.     for index, turtle in enumerate(turtles):
  37.         turtle.color(*turtles[(index + 1) % NUMBER_OF_WEDGES].color())
  38.  
  39.     screen.update()
  40.     screen.ontimer(draw_circle, 1)
  41.  
  42. draw_circle()
  43.  
  44. screen.exitonclick()
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement