Lissajous Curves
Move x with one sine wave and y with another at a different speed, and the point draws a knot whose shape is set by the ratio of the speeds.
How it works¶
A point on a circle is (cos(s), sin(s)): the same speed for x and y. Give them different speeds, x = sin(A × s + π/2) and y = sin(B × s), and the path crosses itself in a pattern set by A : B. A = 3, B = 2 gives a pretzel; 5 : 4 and 7 : 3 give tighter knots. When A and B are whole numbers the curve closes after s goes once round 2π.
The π/2 is the phase: how far ahead the x wave starts. Change it slowly over time and the knot turns over as if it were rotating in 3D; this is what an oscilloscope shows when two tones are played into it.
The C is for the raylib shapes starter.
A = 3, B = 2¶
Change A and B to see the others.
static void draw(float t)
{
const float A = 3, B = 2;
clear(PAPER);
Vector2 last = { 0 };
for (int i = 0; i <= 1260; i++) {
float s = i * 0.005f;
Vector2 p = { W / 2 + 240 * sinf(A * s + PI / 2), H / 2 + 240 * sinf(B * s) };
if (i) DrawLineEx(last, p, 3, INK);
last = p;
}
}
function draw(t) {
const A = 3, B = 2;
clear(PAPER);
let last = Vector2(0, 0);
for (let i = 0; i <= 1260; i++) {
let s = i * 0.005;
let p = Vector2(W / 2 + 240 * sinf(A * s + PI / 2), H / 2 + 240 * sinf(B * s));
if (i) DrawLineEx(last, p, 3, INK);
last = p;
}
}
Turning over: the phase moves with time¶
static void draw(float t)
{
const float A = 5, B = 4;
clear(PAPER);
Vector2 last = { 0 };
for (int i = 0; i <= 1260; i++) {
float s = i * 0.005f;
Vector2 p = { W / 2 + 240 * sinf(A * s + t * 0.3f), H / 2 + 240 * sinf(B * s) };
if (i) DrawLineEx(last, p, 3, INK);
last = p;
}
}
function draw(t) {
const A = 5, B = 4;
clear(PAPER);
let last = Vector2(0, 0);
for (let i = 0; i <= 1260; i++) {
let s = i * 0.005;
let p = Vector2(W / 2 + 240 * sinf(A * s + t * 0.3), H / 2 + 240 * sinf(B * s));
if (i) DrawLineEx(last, p, 3, INK);
last = p;
}
}
Related¶
- Points on a Circle: the same speed for both.
- Motion Trails: a dot following this curve, leaving a trail.