🔬 This loop draws both a rotated line AND its vertical mirror every iteration. What happens if you delete the lines between 'push()' and 'pop()' (the mirrored stroke)? You'll see only half as many lines in the pattern.
for (let i = 0; i < symmetry; i++) {
rotate(angleStep);
// Original stroke
line(mx, my, pmx, pmy);
// Mirrored stroke (flip vertically)
push();
scale(1, -1);
line(mx, my, pmx, pmy);
pop();
}
🔬 These two lines make strokes thicker when the mouse is close to center (d is small). What happens if you swap the 12 and 1? Now close strokes will be thin and far strokes will be thick—the opposite of normal.
const d = dist(0, 0, mx, my);
const sw = map(d, 0, min(width, height) / 2, 12, 1);
function draw() {
// Slightly transparent background for trailing effect (now white)
background(0, 0, 100, 8);
translate(width / 2, height / 2); // center the coordinate system
// Draw the image at the new origin (which is now the center of the canvas)
// The kaleidoscope lines will be drawn on top of this image.
// To make it small, we'll draw it at 50% of its original width and height.
image(centerImage, 0, 0, centerImage.width * 0.5, centerImage.height * 0.5);
if (mouseIsPressed) {
// Mouse position relative to center
const mx = mouseX - width / 2;
const my = mouseY - height / 2;
const pmx = pmouseX - width / 2;
const pmy = pmouseY - height / 2;
// Distance from center controls stroke weight
// The image's size will also affect the effective drawing area,
// so we can adjust the map range if needed.
const d = dist(0, 0, mx, my);
const sw = map(d, 0, min(width, height) / 2, 12, 1);
// Hue cycles over time and with distance
// Increased cycle speed slightly for more "brightness" / change
const hue = (frameCount * 0.8 + d * 0.2) % 360;
// Make saturation 100 for maximum vibrancy, brightness 100 for maximum brightness
stroke(hue, 100, 100, 100); // Full saturation, full brightness
strokeWeight(sw);
noFill();
const angleStep = TWO_PI / symmetry;
// Draw the stroke rotated and mirrored around the center
for (let i = 0; i < symmetry; i++) {
rotate(angleStep);
// Original stroke
line(mx, my, pmx, pmy);
// Mirrored stroke (flip vertically)
push();
scale(1, -1);
line(mx, my, pmx, pmy);
pop();
}
}
// Reset transform to draw UI text in the top-left corner
resetMatrix();
// Text instructions are removed, so no changes needed here.
}