# Clifford Torus — `clifford-torus@1.0.0`

A four-dimensional torus turned and projected into our space: a glowing net of lines that swells, pinches and turns inside out. Loops perfectly.

The Clifford torus lives in four dimensions, so it is shown the way mathematicians show it: turned in four-dimensional space and projected down into ours by stereographic projection. The net of its circles swells into a huge ring, pinches to a point and turns itself inside out, glowing in colours that follow the hidden fourth coordinate. Choose the colours (spectrum, fire, ocean or mono), the number of rings and lines, how solid the skin between them looks, whether it also turns in a second plane, and whether the camera sways.

- Kind: object; status: published; digest sha256:c777122343fe701923bd841a9b1fe8f2f3e66fd7e983f535cc87dd1adad2772b
- Role: Object (3D, three.js): a mind-bending mathematical showpiece for science, music and futuristic content.
- Implementation: three; entry `src/clifford-torus.js`
- Files: https://aipixelwizard.com/registry/clifford-torus/1.0.0/<path> (`LICENSE`, `asset.json`, `demo.js`, `index.html`, `src/clifford-torus.js`)
- Manifest JSON: https://aipixelwizard.com/api/v1/visuals/clifford-torus/versions/1.0.0
- Runnable demo: https://aipixelwizard.com/registry/clifford-torus/1.0.0/index.html (open over http; it imports sibling packages by relative path)
- Dependencies (exact): `three@0.185.1` (source) — Renderer, geometry and shader materials.; `apw-runtime@1.0.0` (demo) — Demo harness.

## Exports
- `createCliffordTorus({ palette?, rings?, lines?, skin?, plane? }) => { group, setProgress(progress), dispose() }` — The projected torus (lines and a faint skin) as a group about 6 across; render through createBloomPass.
- `createBloomPass(renderer, { width, height, glow?, exposure?, grain? }) => { render(scene, camera, output?), dispose() }` — A small bloom with an anti-aliased, depth-tested scene target.
- `PALETTES: { spectrum, fire, ocean, mono }` — Colour schemes for the hidden coordinate.

## Parameters
- `palette` (select one of spectrum | fire | ocean | mono, default "spectrum") — Colours
- `rings` (integer 12–60, default 36) — Rings
- `lines` (integer 24–120, default 72) — Lines
- `skin` (number 0–1, default 1) — Skin
- `plane` (integer 0–1, default 0) — Second turn: 0 turns it in one plane, 1 also in a second plane at twice the speed.
- `orbit` (boolean, default true) — Camera sway

## Composition
- Inputs: Time within the loop; the colours, rings, lines, skin, second turn and camera sway.
- Outputs: A full frame rendered in 3D through an anti-aliased bloom.
- Coordinates: The torus x = cos a, y = sin a, z = cos b, w = sin b (all over √2) is turned in 4D, then projected by (x, y, z) / (1.02 − w) and scaled by 1.6; the camera sits 15 away.
- Lighting: Self-lit lines and an additive skin; the bloom gives the glow.
- Timing: setProgress(progress) rewrites every vertex; frames render in any order.
- Works with: kinetic-title, number-reveal
- Vertex colour follows w; lines are every second ring and every third longitude; the projection's denominator is clamped at 0.3 so the point at w = 1 does not fly to infinity.

## Output and loop
- 1080×1080, 30 fps, 16 s, procedural
- Seamless loop: yes — The torus is turned by a whole circle in the x–w plane (and two circles in the y–w plane if chosen) per loop, so the last frame meets the first; the camera sway is a sine of the loop.
- Verified 2026-10-06 in Chrome 154.0.8037.97 headless on Linux 7.0.0-38-generic (x64), Node 22.14.0 (WebGL 2 via SwiftShader (software)); deterministic: yes; loop check: Frame 0 vs end state (progress 1): mean |Δ| 0.0000, max |Δ| 0 of 255.

## Use it
New project: Create a WebGLRenderer, createCliffordTorus() and createBloomPass(renderer, { width, height }); each frame call torus.setProgress(progress) and bloom.render(scene, camera).

Existing project: Copy src/clifford-torus.js; add torus.group to your scene and render it through createBloomPass.

Reuse ideas:
- Maths explainer: Spectrum, one turn.
- Futuristic title: Fire, two turns.
- Calm science loop: Ocean, fine net.

## Limitations
- A projection of a 4D object is inevitably distorted: sizes near the pinch point are exaggerated and clamped.
- Lines and skin are additive, so overlapping parts blow out to white.

## License
MIT. Copyright (c) 2026 AI Pixel Wizard. Released under the MIT License. See LICENSE in this folder.

Provenance: Adapted from the owner's threejs-sketches/geometry-math/clifford-torus (MIT) and rebuilt for AI Pixel Wizard in October 2026 as an original object: a 4D rotation of the flat torus with stereographic projection, colour by the hidden coordinate and an exact loop.

