Spinning circles that draw a curve: an exact Fourier transform, pure SVG and CSS animation, measurable error and freehand sketch decomposition.

Spinning circles that draw a curve: an exact Fourier transform, pure SVG and CSS animation, measurable error and freehand sketch decomposition.
<svg> with zero <canvas> elements and zero external network requests (performance.getEntriesByType("resource").length === 0), and the drawing + epicycles span at least 65% of screen height.harmonics from 4 to 40 strictly reduces measured rmsErrorPx by at least 75% (ending under 4.0 px).t: 0 -> 2*pi) keeps the SVG pen nib within 0.5 px of the analytic Fourier sum at every sampled frame and increments loopsCompleted by exactly 1.customSketches by 1, and reconstructs the submitted vertices within 6 px RMS at 36 harmonics.FOURIER SCRIBE: Spinning Epicycles Draw Live
HOOK OBJECT: window.__fourier
Build "FOURIER SCRIBE": an illuminated drafting-table epicycle machine in pure SVG and CSS (no canvas, no WebGL, no libraries). A live Discrete Fourier Transform decomposes any closed silhouette — from a compass rose, sailing ship, grand treble clef, or your own freehand mouse/finger sketch — into a chain of spinning brass-and-ink epicycle gears whose final pen tip traces the exact picture in glowing crimson ink.
LOOK
- Style: architectural brass drafting vellum, palette warm cream vellum #F4ECDC, drafting grid #DDD1B8, compass ink #253242, brass circle #C49545, glowing stylus trail #C83E32, ghost blueprint #5B7898.
- Subject: a full-viewport SVG drafting sheet with fine millimeter rulings, a chain of up to 48 nested rotating SVG circles (`<circle>`) and radial brass arms (`<line>`) sorted from largest amplitude to smallest, a glowing pen nib drawing the reconstructed closed `<path>` in real time, and a faint target guide underneath.
- FIRST FRAME (t = 0, no input): the drafting table and spinning epicycle chain (already 35% through tracing the Compass Rose so both the nested gears and crisp ink trail read immediately) fill at least 72% of the screen height, with clean top-left telemetry away from the drawing.
MOTION / PLAY
- Controls: click/drag directly on the vellum to sketch any custom closed shape (on release, the real DFT computes exact complex Fourier coefficients and immediately begins redrawing your sketch with spinning circles!); keys 1–4 or shape buttons switch built-in vector paths (COMPASS ROSE, CLIPPER SHIP, GRAND CLEF, BUTTERFLY); +/- or a harmonics slider varies active epicycles from `N = 3` (blobby low-pass) up to `N = 48` (razor-sharp reconstruction); Space pauses/resumes; `setCamera(panX, panY, zoom)` zooms smoothly into the spinning tip!
- Exact Discrete Fourier Transform: real complex DFT `X[k] = (1/M) * sum(z[m] * exp(-i*2*pi*k*m/M))` computed in code over the sampled contour points, sorted by descending magnitude `|X[k]|`, reconstructing `z(t) = sum(X[k] * exp(i*k*t))` with zero hardcoded circle animations!
- ATTRACT MODE: with no input, a hands-free 28–30 s drafting showcase runs on load: completes the Compass Rose while ramping harmonics from 6 -> 48 so viewers watch the crude loop sharpen into crisp artwork, switches to Clipper Ship, then Grand Clef, zooming briefly onto the tiny fast outer gears. Any input takes over; after 8 s idle it resumes.
SOUND
- Spinning epicycles -> soft harmonic chord built from the top 4 active Fourier frequencies (changes timbre as you raise or lower harmonics!).
- Pen tip tracing fast curves -> delicate pencil-on-vellum scratch modulated by tip speed.
- Completed closed loop -> crisp drafting-bell chime; switching shapes -> paper-turn rustle.
COUNTERS
stats() returns { fps, harmonics, loopsCompleted, shapesDrawn, rmsErrorPx, customSketches }.
- harmonics: exact number of currently active spinning epicycle circles (`3` to `48`).
- loopsCompleted: +1 each time the phase wraps a full `2*pi` cycle and closes the ink curve. Never on load.
- shapesDrawn: count of distinct shapes reconstructed (starts at 1, +1 on each shape switch or custom sketch).
- rmsErrorPx: real measured root-mean-square pixel distance between the `harmonics`-term Fourier reconstruction and the target contour!
- customSketches: +1 each time a user/scripted freehand sketch is transformed via DFT and drawn.
- On screen: top-left pill "EPICYCLES NN · RMS ERROR N.N px · LOOPS N · SHAPE <NAME>", never over the drawing.
CHECKS for ?test=1
With ?test=1, run an accelerated self-test that measures real positions and real events (not self-set flags) and logs "TEST n PASS" or "TEST n FAIL: reason" to the console and to window.__testResults:
1. Pure SVG & framing: the scene uses `<svg>` with zero `<canvas>` elements and zero external network requests (`performance.getEntriesByType("resource").length === 0`), and the drawing + epicycles span at least 65% of screen height.
2. Exact DFT convergence: on the Compass Rose, raising `harmonics` from `4` to `40` strictly reduces measured `rmsErrorPx` by at least 75% (ending under 4.0 px).
3. Tip continuity & closure: stepping one full cycle (`t: 0 -> 2*pi`) keeps the SVG pen nib within 0.5 px of the analytic Fourier sum at every sampled frame and increments `loopsCompleted` by exactly 1.
4. Custom sketch DFT: submitting a synthetic square/star stroke computes new Fourier coefficients, increments `customSketches` by 1, and reconstructs the submitted vertices within 6 px RMS at 36 harmonics.
5. Attract showcase: advancing 28 s hands-free visits >= 3 distinct shapes, completes >= 2 full loops, and logs zero console errors.
KEEP IT SHORT
- Keep the whole file under about 1,500 lines (soft target) so you can write it in one pass and finish well inside 15 minutes.
- Save lines with helpers, loops and instancing, not by dropping features. Everything above must really work: no placeholders, no TODOs.
BUILD RULES (all required):
- Deliver ONE self-contained HTML file: inline CSS and JS, no build step, no local assets. Libraries only from a CDN. If you use Three.js, use exactly this import map: {"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js","three/addons/":"https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"}}
- It must open straight from disk in desktop Chrome and on an iPhone (Safari), fill the full screen, handle resize and touch, and stay smooth (target 60 fps).
- It must look stunning in the very FIRST frame: no black screen, no loading wait, no tiny subject. The main subject fills at least 50% of the screen height.
- SOUND (required): all sound is made in code with Web Audio (no audio files). Show a small "🔊 TAP FOR SOUND" chip; on the first tap create ONE AudioContext, route everything through a master gain of 0.6 into a DynamicsCompressor, and hide the chip. Also expose enableAudio() on the hook object named at the top.
- Expose the hook object named at the top with: setCameraOrbit(azimuthDeg, elevationDeg, distance) (or an equivalent camera setter), advance(seconds) that steps the simulation exactly that much for still captures, enableAudio(), and stats() returning {fps, ...the counters named above}. Use a fixed random seed of 360 so every run is the same.
- Every on-screen counter must count a real event you can see happen. No fake numbers.
- No text overlapping the subject; any label must be readable in a paused frame.
- No brand logos, no real people, no copyrighted characters, brand names or logos.
FAILURE MODES TO AVOID
- Hardcoding fake spinning circles instead of running a real Discrete Fourier Transform on the contour points.
- Using a `<canvas>` element when the prompt specifies pure SVG + CSS.
- Unsorted epicycles where huge and tiny circles jitter chaotically instead of cascading smoothly from largest to smallest.
- `rmsErrorPx` faked or stuck at a constant instead of decreasing visibly as harmonics increase.
- Labels covering the epicycle chain or traced silhouette.
- The same variable declared twice, or methods called on objects that don't exist yet.
SELF-TEST LOOP
- If you can run code: build the file, open it, read the console, run ?test=1, and take screenshots at 3 s, 10 s and 30 s at 1280x720 and 390x844. Look at the screenshots and fix what looks wrong. Fix and retest until all 5 checks pass with zero console errors. Mark anything you could not run as UNMEASURED; never invent results.
- If you are chat-only: go through this prompt line by line, check your code against each line, and fix anything that would fail. Then write one corrected, complete file.
- Final answer: ONE complete HTML file in ONE code block, then the 5 checks marked PASS, FAIL or UNMEASURED. No snippets, no "rest unchanged".
Built one? Post it on X and tag @wikiwaynePost on X