import turtle
import math

# Setup the turtle
turtle.speed(0)
turtle.bgcolor("black")
turtle.pensize(2)

# Parameters for the spirograph
R = 100  # Radius of the larger circle
r = 50   # Radius of the smaller circle
d = 70   # Distance from the center of the smaller circle to the tracing point

# Draw the spirograph
for angle in range(0, 361, 5):
    theta = math.radians(angle)
    x = (R - r) * math.cos(theta) + d * math.cos(((R - r) / r) * theta)
    y = (R - r) * math.sin(theta) - d * math.sin(((R - r) / r) * theta)
    turtle.goto(x, y)
    turtle.color("white")
    turtle.dot()

# Hide the turtle
turtle.hideturtle()

# Keep the window open until it's closed by the user
turtle.done()

Leave a Reply

Your email address will not be published. Required fields are marked *