What is Lucid Geometry?

While pure geometry speaks in the language of perfection, its voice can feel distant. Here, we coax a more organic, lucid flow from its rigid forms. This application is a digital canvas where simple rules blossom into surprising and intricate beauty.

Inspiration

We all had Spirograph as children. I still have mine. It’s magic that rigid gears, wheels, holes, and a pen can create such beautiful shapes. Organic shapes. Spirograph makes the discrete (numbers, lengths, sizes, angles) into something continuous and flowing.

Lucid Geometry is a modern, three-dimensional evolution of that idea. Instead of gears and pens, we use rotating vectors. Instead of a flat piece of paper, we have three-dimensional space. The core principle remains the same: create complexity and beauty from a simple set of instructions.


Controls

Main Controls

  • Randomize: Generates a new set of random segments using the Randomizer Configuration panel.
  • Add Segment: Appends a new segment (a “wheel”) to the list.
  • Share: Copies a URL to your clipboard that encodes your current creation: segments, environment, material, and thickness.
  • Fullscreen: Toggles a fullscreen view of the 3D canvas.

On small screens, the full set of controls lives behind the Settings button.

3D Viewport

  • Rotate: Left-click and drag.
  • Pan: Right-click and drag.
  • Zoom: Scroll with your mouse wheel or trackpad.

Display Options

  • Rotation Speed: How fast the whole shape slowly tumbles (0 to 5; 0 stops it).
  • Thickness: The radius of the tube. It is relative to the shape’s size, so the same value looks the same on large and small shapes.
  • Environment: The High-Dynamic-Range Image (HDRI) that surrounds the scene. It provides both the background and the lighting and reflections.
  • Material: The surface of the tube, from metals (Gold, Silver, Copper, and others) to transparent gems (Glass, Diamond, Ruby, Sapphire) and glowing finishes.

Wheels (Segment Editor)

Each row is one segment. You can add as many as you like.

  • Length: The length of this segment’s spinning arm. It can be negative, which starts the arm pointing the opposite way (a half-turn head start).
  • LFO (s): The period, in seconds, of a slow “breathing” animation on this segment’s length. Set it to 0 to switch the animation off for that segment.
  • Ratio: The rotation speed, as a fraction numerator / denominator. The numerator can be from −64 to 64 (0 is not allowed) and the denominator from 1 to 64. A negative numerator reverses the direction of rotation, which unlocks a whole family of curves.
  • Axis: The axis (XX, YY, or ZZ) the arm spins around.

Because the final shape is a sum (see below), the order of the rows does not matter.

Randomizer Configuration

This panel sets the ranges the Randomize button draws from: the number of segments, lengths, numerators, denominators, and LFO periods. The defaults are 3 segments, lengths 1 to 10, numerators −7 to 7, denominators 1 to 7, and LFO periods of 30 to 50 seconds.

The randomizer never picks a numerator of 0 and avoids repeating the same reduced ratio twice. With three or more segments, it uses every axis at least once, so random shapes are always genuinely three-dimensional.


Outside and Inside Curves

This is directly inspired by how a physical Spirograph works. Take two segments on the same axis. They stay in one plane and draw a flat, Spirograph-style curve.

Outside curves (epitrochoids): When both speeds have the same sign, the arms turn the same way. This is equivalent to rolling a small circle around the outside of a larger one. The result tends to be looping, outward-reaching shapes.

Inside curves (hypotrochoids): When the speeds have opposite signs, the arms turn in opposite directions. This is equivalent to rolling a circle inside a larger one. The result tends to be inward-folding, star-like shapes.

Symmetry: For whole-number speeds aa and bb, the curve has exactly k=∣a−b∣k = |a - b|-fold rotational symmetry. For example, an arm of length 5 at speed 1 combined with an arm of length 4 at speed −6 gives a 7-fold flower: ∣1−(−6)∣=7|1 - (-6)| = 7.

Smooth, pointed, or looped: What decides the look is how fast each arm’s tip actually moves, which is its length times its speed.

  • If the slower-tipped arm dominates (∣L1s1∣>∣L2s2∣|L_1 s_1| > |L_2 s_2|), the curve is smooth and wavy.
  • If they are equal (∣L1s1∣=∣L2s2∣|L_1 s_1| = |L_2 s_2|), the curve has sharp cusps. These are the classic cycloids.
  • If the other arm dominates (∣L1s1∣<∣L2s2∣|L_1 s_1| < |L_2 s_2|), the curve forms loops or petals.

In the example above, 5×1<4×65 \times 1 < 4 \times 6, so the 7 lobes are looped petals.

In Lucid Geometry, you can freely mix segments across different axes. This creates 3D forms that have no equivalent in the flat world of the original Spirograph.


Technology and Mechanism

The shapes in Lucid Geometry are generated by summing a series of rotating vectors. This is the same idea as epicycles, and it’s a finite Fourier series. Each segment acts as an independent rotating arm, and their combined motion draws the final shape.

The Core Concept

Imagine a set of arms, all anchored at the center of our 3D world. Each arm has a length, a rotational speed, and an axis. They all spin simultaneously and independently.

The final path is traced by the point you get from adding all the arm vectors together. You can picture this as joining them tip to tail. Because vector addition doesn’t care about order, the order of the segments does not matter.

In Spirograph terms, it’s like having several wheels, each with its own arm, where the pen sits at the sum of where all the arms point.

Epicycloids and Hypocycloids

The two fundamental families of Spirograph curves have precise mathematical names, and both are fully expressible here.

An epicycloid is traced by a point on the rim of a circle rolling around the outside of a fixed circle. A hypocycloid is the same thing rolling inside. When the pen is not exactly on the rim, as with most Spirograph holes, you get the more general epitrochoids and hypotrochoids.

The true cycloids are the cusped case from above, ∣L1s1∣=∣L2s2∣|L_1 s_1| = |L_2 s_2|. Some recipes using two segments on the same axis:

CurveSpeedsLengths
Deltoid (3 cusps)11 and −2-222 and 11
Astroid (4 cusps)11 and −3-333 and 11
Hypocycloid with kk cusps11 and −(k−1)-(k-1)k−1k-1 and 11
Cardioid (1 cusp)11 and 2222 and 11
Epicycloid with kk cusps11 and k+1k+1k+1k+1 and 11

Fractional speeds work too: speeds 11 and −13-\tfrac{1}{3} with lengths 11 and 33 also give an astroid. Only the ratio of the speeds matters to the shape.

In Lucid Geometry, these families extend into three dimensions. If you put segments on different axes, you can create forms that are impossible on a flat sheet of paper: helical roses, spiralling stars, and tangled knots.

The Math Behind the Magic

The algorithm computes the position of a point at thousands of evenly spaced moments in time, then joins them into a smooth tube.

Step 1: Simplify Speed Ratios

For each segment ii, the speed is the ratio you provide:

si=nidis_i = \frac{n_i}{d_i}

For the timing calculation, each ratio is reduced to lowest terms using the greatest common divisor (GCD). For example, 4/64/6 becomes 2/32/3. Only the reduced denominator matters for how long the shape takes to close.

Step 2: Calculate the Period

To form a closed loop, every arm must return to its starting position at the same moment.

An arm with reduced speed n/dn/d returns home after time 2πd/∣n∣2\pi d / |n|. That always divides evenly into 2πd2\pi d. So if we let

T=2π⋅lcm(d1,d2,…,dn),T = 2\pi \cdot \mathrm{lcm}(d_1, d_2, \ldots, d_n),

every arm completes a whole number of turns at time TT, and the path closes seamlessly. Equivalently, if you measure time in units of T/2πT / 2\pi, every speed becomes a whole number. The shape is then a finite Fourier series, which is always a closed curve.

Step 3: Complexity Caps

Denominators that share no common factors make the LCM grow quickly. For example, lcm(5,7,9)=315\mathrm{lcm}(5, 7, 9) = 315. To keep things responsive, two hard limits apply:

  • Maximum LCM: 512
  • Maximum points: 5,000

If the LCM exceeds 512, the shape is traced only up to T=2π⋅512T = 2\pi \cdot 512. In that case it won’t close naturally, so the last point is joined back to the first. You’ll see a warning in the browser console when either cap applies.

Step 4: Determine Point Density

The path is sampled at a fixed density of 500 points per unit of time. This is subject to the cap:

N=min⁡(⌊500⋅T⌋, 5000),Δt=TNN = \min\left(\left\lfloor 500 \cdot T \right\rfloor,\ 5000\right), \qquad \Delta t = \frac{T}{N}

Even an LCM of 2 gives 500⋅4π≈6283500 \cdot 4\pi \approx 6283 points, so in practice most shapes use exactly 5,000 points. Shapes with long periods therefore have their points spread more thinly, and the smooth spline in Step 6 fills in between.

Step 5: Generate Each Point

For each time t=0,Δt,2Δt,…t = 0, \Delta t, 2\Delta t, \ldots up to TT, the position P⃗(t)\vec{P}(t) is the sum of every segment’s contribution.

For each segment ii:

a) Rotation angle

θi(t)=si t\theta_i(t) = s_i \, t

b) Base arm vector. This is a vector perpendicular to the segment’s axis, with magnitude equal to its length LiL_i:

  • Axis XX: v⃗i=(0,Li,0)\vec{v}_i = (0, L_i, 0), which spins in the YZYZ plane.
  • Axis YY: v⃗i=(0,0,Li)\vec{v}_i = (0, 0, L_i), which spins in the ZXZX plane.
  • Axis ZZ: v⃗i=(Li,0,0)\vec{v}_i = (L_i, 0, 0), which spins in the XYXY plane.

c) Rotate the arm. The base vector is rotated by θi(t)\theta_i(t) about its axis:

v⃗i(t)=R(a^i,θi(t)) v⃗i\vec{v}_i(t) = R(\hat{a}_i, \theta_i(t))\,\vec{v}_i

d) Sum.

P⃗(t)=∑i=1nv⃗i(t)\vec{P}(t) = \sum_{i=1}^{n} \vec{v}_i(t)

Written out in full, each coordinate is a sum of sines and cosines:

P⃗(t)=(∑ZLicos⁡sit  +  ∑YLisin⁡sit∑ZLisin⁡sit  +  ∑XLicos⁡sit∑XLisin⁡sit  +  ∑YLicos⁡sit)\vec{P}(t) = \begin{pmatrix} \sum_{Z} L_i \cos s_i t \;+\; \sum_{Y} L_i \sin s_i t \\[4pt] \sum_{Z} L_i \sin s_i t \;+\; \sum_{X} L_i \cos s_i t \\[4pt] \sum_{X} L_i \sin s_i t \;+\; \sum_{Y} L_i \cos s_i t \end{pmatrix}

Here ∑X\sum_X means “sum over the segments on axis XX”, and so on. So a 3D shape is three flat Spirograph curves, one in each coordinate plane, added together. When every segment shares one axis, two of these vanish and you get a classic flat Spirograph. This puts the shapes in the same family as Lissajous curves and Fourier knots.

Step 6: Build the Tube

The points are joined with a closed Catmull–Rom spline, which is a smooth curve that passes through every point. A tube is then swept along that spline. Finally, the shape is scaled so its largest dimension is always the same size on screen, and the tube radius is adjusted to match. That is why Thickness looks consistent from shape to shape.

Step 7: Animate (LFO)

Each segment with a non-zero LFO period has its length gently modulated over time:

Li(τ)=Li(1+sin⁡ ⁣(2πτperiodi+φi))L_i(\tau) = L_i \left(1 + \sin\!\left(\frac{2\pi \tau}{\text{period}_i} + \varphi_i\right)\right)

Here τ\tau is real (wall-clock) time and φi\varphi_i is a random starting phase. Each length swings between 00 and twice its set value. The whole path and tube are recomputed every frame while this runs.

A Note on Quaternions

Each arm is rotated using a quaternion, built from the segment’s axis and angle. In this particular case, it’s a convenience rather than a necessity.

Every segment rotates about a single, fixed coordinate axis. That is mathematically just a 2D rotation, a cosine and a sine, in one coordinate plane. Because rotations are never chained one after another, gimbal lock can’t arise. Gimbal lock is a problem with composing Euler angles, not with single-axis rotations.

Quaternions are used because Three.js provides them, and they give one uniform code path for all three axes. They would become genuinely valuable if arms were ever allowed to spin around arbitrary or moving axes.


Three.js Integration

The 3D visualization is powered by Three.js, a JavaScript library for 3D graphics in the browser built on WebGL.

Scene, Camera, and Renderer: A Scene holds the objects, a PerspectiveCamera views them, and a WebGLRenderer draws to the canvas. It uses ACES Filmic tone mapping and sRGB output for natural-looking highlights.

Generating the Geometry: The computed Vector3 points become a closed CatmullRomCurve3. That curve is passed to TubeGeometry, which sweeps a circular cross-section along it. The tube is rebuilt whenever the segments change, and every frame while an LFO is active.

Physically Based Materials: Surfaces use MeshPhysicalMaterial. Metals use high metalness and low roughness. Gems use transmission with a real index of refraction (ior): 1.5 for glass, 1.77 for ruby and sapphire, and 2.418 for diamond. Some finishes add a clearcoat layer or an emissive glow.

Environment Lighting: Lighting comes from HDRIs: .hdr files are loaded with RGBELoader and .exr files with EXRLoader. Each file wraps the scene in a 360° image that serves as both the background and the light reflected and refracted by the tube. A directional light adds soft shadows.

Interactive Controls: Camera rotate, pan, and zoom are handled by the OrbitControls add-on.

The Rest of the Stack

Site: Built with Astro. The pages are static HTML, and the 3D canvas and controls are React islands that load in the browser. This page’s math is typeset with KaTeX at build time. Styling uses Tailwind CSS.

No backend: Shared links store your creation directly in the URL, as base64-encoded JSON in the config parameter. Nothing is saved on a server.

Hosting: Static files are served from Amazon S3 through the CloudFront CDN, with infrastructure defined in AWS CDK. The source is on GitHub under the MIT license.