Symmetry and Kaleidoscopes
Feed a pattern a mirrored position and almost anything looks designed: abs(x − centre) for a mirror, a folded angle for a kaleidoscope.
How it works¶
abs(x − 150) is the same for a pixel 30 to the left of the centre line and one 30 to the right, so whatever the pattern does with it, the left half mirrors the right. Do the same to y as well for a four-way mirror.
A kaleidoscope folds the angle instead. Turn the position into polar coordinates (angle and distance), fold the angle into one slice of 2π / n, and turn it back. ((a % seg) + seg) % seg is the angle's position inside its slice, made positive (in C and JavaScript % of a negative number is negative); subtracting half a slice and taking abs mirrors each slice, so neighbours meet without a seam.
The C is for the raylib pixels starter.
Mirror¶
static RGB shade(float x, float y, float t)
{
return rainbow(noise2(fabsf(x - 150) * 0.02f, y * 0.02f) * 1.5f);
}
function shade(x, y, t) {
return rainbow(noise2(fabsf(x - 150) * 0.02, y * 0.02) * 1.5);
}
Four-way mirror¶
static RGB shade(float x, float y, float t)
{
return rainbow(noise2(fabsf(x - 150) * 0.02f, fabsf(y - 150) * 0.02f) * 1.5f);
}
function shade(x, y, t) {
return rainbow(noise2(fabsf(x - 150) * 0.02, fabsf(y - 150) * 0.02) * 1.5);
}
Kaleidoscope, 8 slices¶
static RGB shade(float x, float y, float t)
{
float a = atan2f(y - 150, x - 150);
float d = dist(x, y, 150, 150);
float seg = 2 * PI / 8;
a = fabsf(fmodf(fmodf(a, seg) + seg, seg) - seg / 2); /* fold into one slice */
return rainbow(noise2(d * cosf(a) * 0.02f, d * sinf(a) * 0.02f) * 1.5f);
}
function shade(x, y, t) {
let a = atan2f(y - 150, x - 150);
let d = dist(x, y, 150, 150);
let seg = 2 * PI / 8;
a = fabsf(fmodf(fmodf(a, seg) + seg, seg) - seg / 2); // fold into one slice
return rainbow(noise2(d * cosf(a) * 0.02, d * sinf(a) * 0.02) * 1.5);
}
A turning kaleidoscope¶
Time as noise's third input changes what is in the slice; adding it to the angle turns the whole thing.
static RGB shade(float x, float y, float t)
{
float a = atan2f(y - 150, x - 150) + t * 0.1f;
float d = dist(x, y, 150, 150);
float seg = 2 * PI / 6;
a = fabsf(fmodf(fmodf(a, seg) + seg, seg) - seg / 2);
return acid(noise3(d * cosf(a) * 0.02f, d * sinf(a) * 0.02f, t * 0.2f) * 1.5f);
}
function shade(x, y, t) {
let a = atan2f(y - 150, x - 150) + t * 0.1;
let d = dist(x, y, 150, 150);
let seg = 2 * PI / 6;
a = fabsf(fmodf(fmodf(a, seg) + seg, seg) - seg / 2);
return acid(noise3(d * cosf(a) * 0.02, d * sinf(a) * 0.02, t * 0.2) * 1.5);
}
Related¶
- Angle around a Point: polar coordinates.
- Points on a Circle: from angle and distance back to x and y.