Spirograph (Epitrochoids and Hypotrochoids!)
Author: Marc Renault

Hide circles

Fixed circle radius

Rolling circle radius

Arm length (as multiple of r)

Draw!

Run animation

t = 0 (slider from 0 to 1, step 0.0030)
d = 1.25 (slider from 0 to 3, step 0.05)
R = 60 (slider from 1 to 80, step 1)
r = 16 (slider from -60 to 60, step 1)
numrevs = Max(1.0, abs(r) / GCD[R, abs(r)])
theta: 2.0 * 3.142 t numrevs
Cx(x) = (R + r) cos(x)
Dx(x) = -1.0 d r cos((R + r) x / r)
Px(x) = Cx(x) + Dx(x)
Dy(x) = -1.0 d r sin((R + r) x / r)
Cy(x) = (R + r) sin(x)
C: (Cx(theta), Cy(theta))
Py(x) = Cy(x) + Dy(x)
P: (Px(theta), Py(theta))
CR = Circle((0.0, 0.0), R)
Cr = Circle(C, abs(r))
Spiro = CurveCartesian(Px(T), Py(T), T, 0.0, theta)
a = false
txtCurveType = If(r ≟ 0.0 ∨ d ≟ 0.0, "Circle!", If[r > 0.0, If[d ≟ 1.0, "Epicycloid", "Epitrochoid"], If[d ≟ 1.0, "Hypocycloid", "Hypotrochoid"]])
armsegment = Segment(C, P)
text5: "R = " + R
text6: "r = " + r
text7: d + ""