Infinite Reflections: Simulating a 3D Kaleidoscope with py5

2026/8/17

The kaleidoscope, invented in 1816, is a triumph of optical geometry. By arranging mirrors at specific angles, it transforms chaotic, random fragments into breathtaking radial symmetry. "Kinetic Kaleidoscope Mirror Room 3D" brings this analog optical illusion into a digital, volumetric space. Instead of calculating complex, computationally heavy ray-traced reflections, this sketch uses matrix transformations in Python and py5 to procedurally generate a mesmerizing, infinite flight through a neon mirror room.The visual result is a high-speed journey down a glowing, six-sided tunnel. Neon cyan, magenta, and lime shards spin and pulse as they fly past the camera, perfectly mirrored across six axes of symmetry. Additive blending ensures that where the shards overlap in the dense center of the tunnel, they burn with intense, white-hot light.

Visual & Aesthetic Approach

The aesthetic of this piece is pure cybernetic psychedelia. The foundation of the look relies on extreme contrast: a pitch-black background populated by highly saturated, primary-colored geometry (cyan, magenta, lime).To achieve the "glowing" neon effect without using expensive post-processing bloom shaders, the sketch utilizes py5.blend_mode(py5.ADD). Furthermore, the opacity of each shard is dynamically modulated by a sine wave based on time:
pulse = py5.sin(t * py5.TWO_PI * 2.0 + i) * 0.5 + 0.5
py5.fill(float(shard_hues[i]), 80, 80, 60 + pulse * 40)
This simple pulse function makes the individual shards throb with light. Because the animation loops exactly once over its 15-second duration (using the normalized time variable t), the pulsing feels rhythmic and hypnotic.

Code & Technical Breakdown

Rendering a true 3D mirror room using ray-tracing requires calculating light bouncing between multiple surfaces, which is too slow for real-time generative art in Python. Instead, we can "fake" the kaleidoscope effect using spatial rotation loops and depth wrapping.

Procedural Radial Symmetry

Instead of drawing the shards once and reflecting them, we draw the exact same set of 200 shards six times, rotating the entire 3D canvas by 60 degrees ($\pi/3$ radians) for each pass.
# 6-fold radial symmetry (like a classic kaleidoscope)
for mirror in range(6):
    py5.push_matrix()
    py5.rotate_z(mirror * py5.TWO_PI / 6.0)
    
    # Draw all 200 shards...
    
    py5.pop_matrix()
By wrapping the shard-drawing logic inside this six-step loop, we guarantee perfect radial symmetry. Because py5.push_matrix() and py5.pop_matrix() isolate the coordinate system, rotating the canvas doesn't permanently distort the space; it merely places the "virtual mirrors" perfectly around the center axis.

Infinite Forward Flight (Z-Wrapping)

To create the illusion of flying endlessly through the kaleidoscope, the camera constantly moves forward along the Z-axis (py5.translate(0, 0, t * 800)). However, if we only moved the camera, we would eventually fly past all the generated geometry and into empty space.To solve this, we use a technique common in particle systems and old-school video games: Z-wrapping.
# Z position moves toward camera and wraps around
pz = shard_pos[i, 2] + t * 800

# If the shard passes behind the camera, teleport it far ahead
if pz > 400:
    pz -= 1200
As a shard flies past the viewer (crossing the threshold of pz > 400), it is instantly teleported 1200 units deep into the background. Because it fades into the dark void in the distance, the viewer never notices the teleportation. This creates a seamless, infinite loop of geometry using only 200 base shards.
kinetic kaleidoscope mirror room 3d p1

Conclusion

"Kinetic Kaleidoscope Mirror Room 3D" demonstrates the power of coordinate system manipulation in generative art. By combining simple matrix rotations with depth wrapping and additive blending, we can trick the eye into seeing infinite reflections and endless depth. It is a digital love letter to a classic optical toy, reimagined for the cybernetic age.