Epitrochoid Animation with Python Turtle

Epitrochoid to Epicycloid is similar to Hypotrochoid to Hypocycloid. Epitrochoid is a generalization of Epicycloid where the tracking point can lie inside or outside the rolling circle. Animate the drawing process of Epitrochoid and experiment with different parameters.

Epitrochoid with BigCircle/SmallCircle=7 and BigCircle/TrackingPoint=13
Epitrochoid with BigCircle/SmallCircle=5.3 and BigCircle/TrackingPoint=2.7
Epitrochoid with BigCircle/SmallCircle=1.1 and BigCircle/TrackingPoint=7.1

What’s next?
Spirograph

Cycloid and Trochoid with Python Turtle

Cycloid is curve formed by tracing a point on a circle while is rolling along a straight line. Animate the drawing process of cycloid.

Cycloid

You can set the tracking point inside the circle or outside the circle to form a more general curve call Trochoid.

Trochoid with Tracking Point Outside the Circle
Trochoid with Tracking Point Inside the Circle

Spirograph with Python Turtle

Continuing from Hypotrochoid project, create program that allows users to draw many Hypotrochoid on one canvas to generate a beautiful spirograph. Ask users to enter the following parameters: the ratio of big circle and small circle, the ratio of big circle and distance to trancing point, and the color. When user enters ‘rainbow’ as color, use colorsys library to use all hues gradually when drawing the curve.

Spirograph Creator Animation
Spirograph Generated with Python Turtle
Spirograph Generated with Python Turtle
Spirograph Generated with Python Turtle

Hypotrochoid Animation with Python Turtle

Hypotrochoid is a curve very similar to Hypocycloid. But it is more general than Hypocycloid because the point we are tracing doesn’t have to lie on the circle. It can be inside or outside the circle, making it possible to create more interesting curves. The following is a few Hypotrochoid curves created with Python Turtle:

BigCircle/SmallCircle=1.9 BigCircle/TracingDistance=1.8
BigCircle/SmallCircle=3.1 BigCircle/TracingDistance=1.9
BigCircle/SmallCircle=4.7 BigCircle/TracingDistance=12.3
BigCircle/SmallCircle=19 BigCircle/TracingDistance=13

Solution:

import turtle
import math

screen = turtle.Screen()
screen.setup(1000,1000)
screen.title("Hypotrochoid with Python Turtle - PythonTurtle.Academy")
screen.tracer(0,0)

turtle.speed(0)
turtle.hideturtle()
turtle.up()
turtle.pensize(2)
t = turtle.Turtle()
t.up()
t.hideturtle()
t.speed(0)
tt = turtle.Turtle()
tt.hideturtle()
tt.speed(0)
first = True

r_big=300
r_small=r_big/2.1
d = r_big/1.6

t3 = turtle.Turtle()
t3.hideturtle()
t3.speed(0)
t3.pensize(2)
t3.up()
t3.seth(0)
t3.goto(0,-r_big)
t3.down()
t3.circle(r_big,steps=200)

tt.up()
tt.pensize(1)
tt.color('red')
first = True

def draw_circle(x,y,angle):
    global first
    turtle.clear()
    turtle.up()
    turtle.seth(0)
    turtle.goto(x,y-r_small)
    turtle.down()
    turtle.color('black')
    turtle.circle(r_small,steps=200)
    turtle.up()
    turtle.goto(x,y)
    turtle.dot(10,'blue')
    turtle.down()
    turtle.seth(angle)
    turtle.color('purple')
    turtle.fd(d)
    turtle.dot(10,'red')
    tt.goto(turtle.xcor(),turtle.ycor())
    if first:
        tt.down()
        first = False

angle = 0
dist = -r_small*angle*math.pi/180
big_radian = dist/r_big
x = (r_big-r_small)*math.cos(big_radian)
y = (r_big-r_small)*math.sin(big_radian)
draw_circle(x,y,angle+big_radian*180/math.pi)
while True:
    angle -= 6
    dist = -r_small*angle*math.pi/180
    big_radian = dist/r_big
    x = (r_big-r_small)*math.cos(big_radian)
    y = (r_big-r_small)*math.sin(big_radian)
    draw_circle(x,y,angle+big_radian*180/math.pi)
    if angle % 360 == 0 and int(round(big_radian*180/math.pi)) % 360 == 0:
        break
    turtle.update()
    
turtle.clear()
t3.clear()
turtle.update()

What’s next?
Spiralgraph