Draw a spirograph using turtle package. You can find the turtle package document in below link turtle — Turtle graphics — Python 3.11.3 documentation import turtle as t import random tim = t.Turtle() t.colormode(255) def random_color(): r = random.randint(0, 255) g = random.randint(0, 255) b = random.randint(0, 255) color = (r, g, b) return color
时间: 2024-01-13 13:05:49 浏览: 110
Sure, I can help you with that! Here's an example code to draw a spirograph using the turtle package:
```
import turtle as t
import random
tim = t.Turtle()
t.colormode(255)
def random_color():
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
color = (r, g, b)
return color
# Set up the initial position and angle
tim.penup()
tim.goto(-200, 0)
tim.pendown()
tim.speed(0)
# Draw the spirograph
for i in range(360):
tim.color(random_color())
tim.circle(100)
tim.left(1)
# Hide the turtle when finished
tim.hideturtle()
# Keep the window open until closed manually
t.mainloop()
```
This code will draw a spirograph with a random color for each circle. You can adjust the circle radius, angle, and other parameters to create different spirographs. I hope this helps! Let me know if you have any other questions.
阅读全文
相关推荐














