Visualizations
318 / 500

318 · Generative art

Kaleidoscope

Draw once, and twelve mirrored strokes bloom into a mandala.

Every stroke is drawn in many rotated copies around the center, and each copy is mirrored, using canvas transforms so the drawing code only describes one stroke. Line width follows speed and hue cycles over time. When nobody is drawing, a wandering pen keeps the pattern growing on its own.

Try it. Draw with the pointer. Press C or double-click to clear, and 1 to 9 to change the symmetry.

  • Rotation and reflection transforms
  • Stroke smoothing
  • HSL color cycling

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a kaleidoscope drawing toy with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Paint it a deep navy or near-black background.
- When I drag the pointer, take each small segment of my stroke relative to the center of the canvas and draw it 6 times, rotated by 60 degrees each time with ctx.rotate. Then draw each copy again mirrored with ctx.scale(1, -1), for 12 symmetric strokes.
- Build each segment once as a Path2D and stroke it under each transform, so the drawing code only describes one stroke.
- Cycle the hue over time with hsl() colors, and make the line thinner when I move fast and thicker when I move slowly.
- Press C or double-click to clear, and 1 to 9 to change the number of rotations.

Once that works, make it beautiful:
- Smooth the strokes with quadratic curves through the midpoints of the pointer samples.
- Draw each stroke twice with globalCompositeOperation = "lighter": a wide, faint glow and a thin, bright core.
- Add an autopilot pen that draws when I am idle: in polar coordinates, have it trace petals, scallops and loops in rings that grow outward from the center, so a mandala builds itself.
- Slowly rotate the finished mandala, then fade it out and start a fresh one with a new palette.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as exporting a high-resolution PNG, a mode that draws with dots or shapes, or recording and replaying strokes.
PreviousLeapfrogging VorticesSmoke rings take turns slipping through each other, from pure vortex dynamics. NextFour-Dimensional PolytopesAll six regular 4D polytopes, double-rotating through themselves in stereographic 3D.

Related visualizations

  • KolamGenerative art A hand traces a rice-flour kolam: one unbroken line looping around every dot.
  • Painterly RenderingGenerative art A harbor at dusk repainted coarse to fine in thousands of curved, bristly strokes.
  • Plotter LandscapeGenerative art A mountain range inked stroke by stroke, with exact floating-horizon hidden lines.
  • Differential GrowthGenerative art One closed line grows, buckles and folds into brain coral without ever crossing.
  • Wallpaper GroupsGenerative art Paint once and any of the 17 plane symmetry groups repeats the stroke across the plane.
  • Ink Landscape ScrollGenerative art An endless ink handscroll of misty peaks, pines, pavilions and boats, unrolling.
  • Evolved TrianglesGenerative art Two hundred translucent triangles evolve from chaos into a painted landscape.
  • Pen PlotterGenerative art A SCARA plotter arm inks hatched, hidden-line drawings along a 2-opt optimized route.
  • Palette CyclingRetro A waterfall, harbor rain and an aurora, animated without changing a single pixel.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs