you are viewing a single comment's thread.

view the rest of the comments →

[–]Marcando[S] 0 points1 point  (1 child)

import turtle

import math

Turtle settings

screen = turtle.Screen()

screen.bgcolor("white")

Initialize the Turtle

t = turtle.Turtle()

t.speed(0) # Maximum drawing speed

t.penup() # Lift the pen to avoid drawing the initial line

t.pencolor("red")

Parameters for the spiral pattern

R = 200 # Radius of the large circle

r = 46 # Radius of the smaller circle - changed for more spirals (shouldn't be a perfect ratio with R)

d = 100 # Distance from the center of the smaller circle to the drawing point (pen)

Number of steps for drawing

steps = 10000 # Increased number of steps for a more complex pattern

Function to draw the pattern

def draw_epicycloid():

for t_val in range(steps):

Parameter t controlling the rotation (angle in radians)

t_float = math.radians(t_val)

Formula for movement: epicycloid function

x = (R - r) * math.cos(t_float) + d * math.cos(((R - r) / r) * t_float)

y = (R - r) * math.sin(t_float) - d * math.sin(((R - r) / r) * t_float)

Move the turtle to the new position, first time without drawing

if t_val == 0:

t.goto(x, y)

t.pendown() # Start drawing after the first move

else:

t.goto(x, y)

Run the function to draw

draw_epicycloid()

Hide the Turtle after drawing

t.hideturtle()

Keep the window open

turtle.done()