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 (, , or ) 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 and , the curve has exactly -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: .
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 (), the curve is smooth and wavy.
- If they are equal (), the curve has sharp cusps. These are the classic cycloids.
- If the other arm dominates (), the curve forms loops or petals.
In the example above, , 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, . Some recipes using two segments on the same axis:
| Curve | Speeds | Lengths |
|---|---|---|
| Deltoid (3 cusps) | and | and |
| Astroid (4 cusps) | and | and |
| Hypocycloid with cusps | and | and |
| Cardioid (1 cusp) | and | and |
| Epicycloid with cusps | and | and |
Fractional speeds work too: speeds and with lengths and 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 , the speed is the ratio you provide:
For the timing calculation, each ratio is reduced to lowest terms using the greatest common divisor (GCD). For example, becomes . 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 returns home after time . That always divides evenly into . So if we let
every arm completes a whole number of turns at time , and the path closes seamlessly. Equivalently, if you measure time in units of , 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, . 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 . 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:
Even an LCM of 2 gives 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 up to , the position is the sum of every segment’s contribution.
For each segment :
a) Rotation angle
b) Base arm vector. This is a vector perpendicular to the segment’s axis, with magnitude equal to its length :
- Axis : , which spins in the plane.
- Axis : , which spins in the plane.
- Axis : , which spins in the plane.
c) Rotate the arm. The base vector is rotated by about its axis:
d) Sum.
Written out in full, each coordinate is a sum of sines and cosines:
Here means “sum over the segments on axis ”, 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:
Here is real (wall-clock) time and is a random starting phase. Each length swings between 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.