# Donut Stack — `donut-stack@1.0.0`

A tower of glazed donuts with wavy glossy frosting and sprinkles, turning and wobbling on a plate. Loops perfectly.

A tower of golden donuts on a white plate in warm studio light. Each donut has a wavy glossy frosting layer that thickens into a bead along its edge and a scatter of sprinkles, and the tower turns, sways and wobbles, neighbouring donuts turning in opposite directions. Choose how many donuts, the frosting flavours (classic, pastel or berry), how many sprinkles, the seed, the backdrop colour and whether the camera sways.

- Kind: object; status: published; digest sha256:e1256c606fcf17b5c57dd7513efd3554ed150c476eda0c68c0119328d2abfab7
- Role: Object (3D, three.js): a delicious, playful showpiece for food, bakery and treat content.
- Implementation: three; entry `src/donut-stack.js`
- Files: https://aipixelwizard.com/registry/donut-stack/1.0.0/<path> (`LICENSE`, `asset.json`, `demo.js`, `index.html`, `src/donut-stack.js`)
- Manifest JSON: https://aipixelwizard.com/api/v1/visuals/donut-stack/versions/1.0.0
- Runnable demo: https://aipixelwizard.com/registry/donut-stack/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.; `chrome-material@1.1.0` (demo) — Studio environment light, backdrop and contact shadow.; `apw-runtime@1.0.0` (demo) — Demo harness.

## Exports
- `createDonutStack({ count?, flavours?, sprinkles?, seed? }) => { group, height, setProgress(progress), dispose() }` — The tower of donuts on a plate, base on y = 0; needs an environment map.
- `FLAVOURS: { classic, pastel, berry }` — Frosting colours in stacking order.

## Parameters
- `count` (integer 2–8, default 5) — Donuts
- `flavours` (select one of classic | pastel | berry, default "classic") — Frostings
- `sprinkles` (number 0–1, default 1) — Sprinkles
- `seed` (integer 1–999, default 4) — Seed
- `background` (color, default "#2b2420") — Backdrop
- `orbit` (boolean, default true) — Camera sway

## Composition
- Inputs: Time within the loop; the count, frostings, sprinkles, seed, backdrop and camera sway.
- Outputs: A full frame rendered in 3D with a studio environment.
- Coordinates: The plate (radius 2.75) rests with its base at y = −0.32; the donuts stack from y ≈ 0.4 upward, centred on the y axis; the camera frames the whole tower.
- Lighting: A warm key light with a shadow map and the studio environment.
- Timing: setProgress(progress) sets every donut's turn, tilt and sway; frames render in any order.
- Works with: chrome-material, orbit-camera, kinetic-title, number-reveal
- Frosting is a generated strip over the top of each torus with a wavy border; sprinkles are one instanced capsule mesh per donut.

## Output and loop
- 1080×1080, 30 fps, 16 s, procedural
- Seamless loop: yes — Each donut turns a whole number of times per loop (neighbours in opposite directions), tilts and sways in sines of whole cycles and the camera sway is a sine of the loop, so the last frame meets the first.
- Verified 2026-10-05 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 with a studio environment and a shadow-casting light, add createDonutStack().group and call tower.setProgress(progress) each frame.

Existing project: Copy src/donut-stack.js; add the group to your scene with an environment map.

Reuse ideas:
- Bakery promo: Classic, five donuts.
- Spring colours: Pastel, tall.
- Minimal: Two donuts.

## Limitations
- Donuts do not collide: the tilt is small enough that neighbours touch lightly.
- Sprinkles are flat capsules without much shape variety.

## 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/objects-scenes/donut-stack (MIT) and rebuilt for AI Pixel Wizard in October 2026 as an original studio object: torus dough with vertex-colour baking, a generated wavy frosting strip with a bead edge, instanced sprinkles and a closed-form turn and wobble on an exact loop.

