What happens when elementary school multiplication tables collide with geometry? You get breathtaking geometric art!
Imagine arranging $N$ numbered points ($0, 1, 2, \dots, N-1$) evenly around the perimeter of a circle, just like hours on a clock face.
Now choose a multiplier $M$ (for example, $M = 2$):
For each point $k$, calculate $(k \times M)$.
Wrap the number around the circle using clock arithmetic (modulo $N$):
$$\text{target} = (k \cdot M) \pmod N$$
Draw a straight line segment connecting point $k$ to its target point.
Even though every single stroke is a straight line, the collection of hundreds of lines collectively outlines a smooth glowing curve called an envelope:
$M = 2$ produces a Cardioid (heart shape)—the exact same shape found at the center of the famous Mandelbrot fractal, and in caustic light patterns reflecting off the rim of a coffee mug!
$M = 3$ produces a Nephroid (a 2-lobed kidney shape).
$M = 4$ produces a 3-lobed epicycloid.
In general, an integer multiplier $M$ generates an epicycloid with $(M - 1)$ cusps!
In this lesson, we use gif_circle(0, 0, R, color) and gif_line(x1, y1, x2, y2, color) to animate multiplier $M$ continuously and watch cardioids and nephroids morph smoothly before our eyes!
gif_line(x1,y1,x2,y2,color)
Move the mouse over a dotted box for more information.
Now you try. Try increasing N to 150 or 200 for ultra-sharp caustics, or try stepping M in finer intervals!
Type your code here:
See your results here:
The code has ???? for the number of points N. Replace ???? with 100 and click Run to watch cardioids and nephroids emerge!
Notes:
Envelopes and Caustics: An envelope is a curve that is tangent to each member of a family of lines. Each line is tangent to the cardioid!
Continuous Multipliers: When $M$ is not a whole number (like $2.5$), you see intricate interwoven spiral mandalas.
Trigonometric Coordinates: Any point at angle $\theta$ on a circle of radius $R$ is located at $(R\cos\theta, R\sin\theta)$.
Share your code
Show a friend, family member, or teacher what you've done!