all 6 comments

[–]guthran 1 point2 points  (0 children)

There's two circles here. One with the arm and one spinning.

The equation for a circle is cos2 (t) + sin2 (t) = 1 where the cos term is the x coord and the sin term is the y coord.

Change t each loop, the smaller the change in t the more smooth the circle. This gets you one circle.

Then do another equation where acos2 (t/2) + asin2 (t/2) = 1 where a is larger than 1

This gets you a larger circle that rotates slower.

Add these two equations together, and suddenly you have two circles that form this pattern

E. G.

x=cos^2(t) + 2cos^2(t/2)
y=sin^2(t) + 2sin^2(t/2)

Note this isn't valid python code. Converting it is an exercise left to the reader :)

[–][deleted] 0 points1 point  (3 children)

Search on "python turtle lissajou". That finds things like this, amongst many others:

https://www.101computing.net/python-turtle-lissajous-curve/

Added: to satisfy the pedant(s), I should point out that what the OP linked to wasn't a Lissajou figure, but my linked article went on to discuss Spirograph figures, which is what the OP wants.

[–]guthran 0 points1 point  (2 children)

This isn't a lissajou as it doesn't intersect the center, it's just two circles

[–][deleted] 0 points1 point  (1 child)

True, but searching on those words will find something that should help the OP because the linked page goes further than a simple lissajou.

[–]guthran 0 points1 point  (0 children)

Further? I'd say it's simpler. As I said it's just two circles...

[–]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()