# Recursive Portal — `recursive-portal@1.0.0`

Doorways inside doorways spiral away into a glowing depth, falling in at a steady rate. Loops perfectly.

A doorway with a smaller copy of itself in its opening, and another in that, receding into an endless glowing depth. The whole picture falls in towards the middle at a steady rate, one copy of the doorway passing into the next every loop, and each level turns a little more than the one before, so the corridor spirals as it goes. Doorways can be arches, rectangles or circles. Choose the shape, the colours (ember, ocean, violet or mono), how much smaller each doorway is than the last, the twist per level, the frame thickness and the brightness.

- Kind: background; status: published; digest sha256:3bc799e0ae1c6d2420f8018aa73aaf690260cdf90ccfa4ad20d83304a50deddc
- Role: Shader background (three.js): an infinite-depth Droste corridor for fantasy, portal and transition content.
- Implementation: three; entry `src/recursive-portal.js`
- Files: https://aipixelwizard.com/registry/recursive-portal/1.0.0/<path> (`LICENSE`, `asset.json`, `demo.js`, `index.html`, `src/recursive-portal.js`)
- Manifest JSON: https://aipixelwizard.com/api/v1/visuals/recursive-portal/versions/1.0.0
- Runnable demo: https://aipixelwizard.com/registry/recursive-portal/1.0.0/index.html (open over http; it imports sibling packages by relative path)
- Dependencies (exact): `three@0.185.1` (source) — Renderer and a full-screen shader material.; `apw-runtime@1.0.0` (demo) — Demo harness.

## Exports
- `createRecursivePortal({ shape?, palette?, ratio?, twist?, frame?, brightness? }) => { scene, camera, setSize(width, height), update(time, loopSeconds), dispose() }` — The corridor as one full-screen shader; render its scene with its camera, ideally through createBloomPass.
- `createBloomPass(renderer, { width, height, glow?, exposure?, grain? }) => { render(scene, camera, output?), dispose() }` — A small bloom with tone mapping and a fixed grain.
- `PALETTES: { ember, ocean, violet, mono }` — Wall, depth, frame and glow colours.

## Parameters
- `shape` (select one of arch | rect | round, default "arch") — Doorway
- `palette` (select one of ember | ocean | violet | mono, default "ember") — Colours
- `ratio` (number 0.4–0.8, default 0.6) — Shrink per level
- `twist` (number -0.8–0.8, default 0.25) — Twist: Turn per level, in radians; negative spirals the other way.
- `frame` (number 0.4–2, default 1) — Frame thickness
- `brightness` (number 0.6–1.6, default 1) — Brightness

## Composition
- Inputs: Time within the loop; the doorway shape, colours, ratio, twist, frame thickness and brightness.
- Outputs: A full-frame shader image through a bloom pass.
- Coordinates: Screen-centred, ±1 vertically; every doorway is centred on the origin; level n has scale ratio^n and turns n × twist.
- Lighting: Self-lit: walls shade towards the frame, frames are bevelled, and a glow sits at the far end; the bloom adds to it.
- Timing: update(time, loopSeconds) sets the loop phase; frames render in any order.
- Works with: kinetic-title, number-reveal
- Colour depends only on a level's scale, never on its index, which is what makes the loop exact.

## Output and loop
- 1080×1080, 30 fps, 10 s, procedural
- Seamless loop: yes — The picture is the same after one step of shrinking by the ratio and turning by the twist; over the loop it shrinks and turns by exactly one step, and the number of levels is set from the ratio so the same set of levels is always drawn, so the last frame meets the first.
- 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, createRecursivePortal() and createBloomPass(renderer, { width, height }); call portal.setSize(w, h) and each frame portal.update(time, loopSeconds) then bloom.render(portal.scene, portal.camera).

Existing project: Copy src/recursive-portal.js and render portal.scene with portal.camera into your own target.

Reuse ideas:
- Fantasy transition: Ember arch.
- Sci-fi: Ocean, round, strong twist.
- Clean: Violet rectangle.

## Limitations
- It is a flat self-similar picture, not a 3D corridor: there is no parallax.
- Very high ratios (0.75 and above) draw many levels and are slower.

## 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/abstract-artistic/recursive-portal (MIT) and rebuilt for AI Pixel Wizard in October 2026 as an original shader: a Droste-style self-similar corridor whose colour depends only on scale, falling in by exactly one step per loop, on an exact loop.

