Creative coding kit
The creative coding kit is a set of composable primitives for making procedural ASCII scenes. It turns recipes, drawings, fields, geometry, particles, materials, images, and effects into the same playable piece so an engineer can start with a ready-made scene and refine it without changing the output model.
System model
The kit separates scene intent from frame output. A creator combines sources that describe what should appear, adds time-based behavior or visual treatment, and receives a piece that can be composed again or sent to a renderer.
flowchart LR
A[Recipe or primitive] --> B[Piece]
B --> C[Composition]
C --> D[Effects and motion]
D --> E[ASCII frame]
E --> F[Web, SVG, or terminal]
Piece contract
The piece is the common product of the kit. It has a name, size, category, frame rate, options, and optional colour and loop data. A frame is produced from time t, which lets the same scene support playback, seeking, reduced motion, and export. The kit's piece() builder creates this contract for custom work. src/types.ts• L26-70 src/…/core.ts• L769-795
References: src/types.ts• L26-70 src/…/core.ts• L769-795
Composable sources
Every source can become part of a larger scene. Sources include text, library pieces, fields, drawings, 3D objects, particle systems, materials, images, and SVG drawings. Composition keeps each source's time and options while combining its visible result into a new piece. This makes a background, subject, label, and overlay independent parts of one scene. Scene composition
References: src/…/core.ts• L797-867 src/…/compose.ts• L59-82 src/…/compose.ts• L675-703
Deterministic time
The kit treats time as an input rather than as hidden state. Seeded random values and time-based functions make the same seed and t produce the same frame. Parts can declare a loop, and composition combines compatible loops so an exported animation can repeat without a visible break. src/…/math.ts• L1-16 src/…/compose.ts• L344-379
References: src/…/math.ts• L1-16 src/…/math.ts• L79-85 src/…/compose.ts• L344-379
Primitive families
The families form a progression from high-level scene ideas to direct control of cells. Each family returns a piece or draws into a piece, so creators can mix levels of control in one result.
Recipes and scene assembly
Recipes are named starting points for common looks, motions, and widgets. They hide setup and use shared words for speed, scale, colour, direction, and timing. Scene assembly then places those results in rows, columns, grids, layers, or sequences. Recipes Scene composition
References: src/…/index.ts• L1-21 src/…/compose.ts• L817-1009
Drawing and fields
Drawing primitives turn a cell surface into a direct canvas for text, lines, boxes, curves, plots, and pixel-like marks. A field uses a function of position and time to describe each cell, then maps its value to characters and colours. Together they support both hand-placed diagrams and shader-like procedural scenes. Drawing and fields
References: src/…/draw.ts• L1-15 src/…/draw.ts• L453-470 src/…/field.ts• L97-110 src/…/field.ts• L470-477
Effects and materials
Effects change an existing source without changing the basic piece contract. They can add transitions, scans, glints, waves, colour movement, outlines, or shadows. Materials take the opposite view: they describe what an object is made of and what it emits, then assemble those parts into a picture such as glass with water and bubbles. Effects and materials
References: src/…/fx.ts• L1-10 src/…/fx.ts• L368-411 src/…/materials.ts• L1-18
Particles and simulation
Particle systems describe many moving items through their source, motion, lifetime, bounds, and appearance. Presets cover common weather and energy scenes, while custom systems can emit from a shape or from the visible cells of text or another piece. The system computes each particle from time and seed, so it remains seekable and exportable. Particles and simulation
References: src/…/particles.ts• L1-15 src/…/particles.ts• L89-114 src/…/particles.ts• L164-180
Geometry, images, and vector sources
Geometry primitives provide 3D shapes, cameras, light, textures, and groups that render into the same cell surface as other sources. Image and SVG primitives convert external visual assets into ASCII pieces. SVG parts can also receive named motion or material treatment, which lets a static drawing become a procedural scene. Geometry, math, and images
References: src/…/shapes3d.ts• L1-11 src/…/image.ts• L1-12 src/…/vector.ts• L1-21
Rendering model
The kit renders through a shared cell surface. Each cell carries a character and may carry a palette colour, while empty cells remain available for layers below them. This common surface is the boundary between scene generation and output adapters.
Cell surface
The surface gives all primitives one coordinate space with columns, rows, characters, colours, clipping, writing, filling, and pasting. Character-cell and square-cell sources can be combined while preserving their visual shape. The result can be read as text or as coloured frame data. src/…/core.ts• L537-569 src/…/core.ts• L668-743
References: src/…/core.ts• L537-569 src/…/core.ts• L668-743
Colour and character ramps
Ramps map brightness to characters from light mark to dense mark. Palettes map scene values to colours and can provide separate light-page and dark-page choices. The kit keeps these concerns separate so a scene can preserve its shape while changing its visual treatment for text, colour, paper, or dark output. src/…/core.ts• L79-119 src/…/core.ts• L242-327
References: src/…/core.ts• L79-119 src/…/core.ts• L242-327
Output targets
A kit piece is not tied to one display. The same result can play in a browser or terminal, mount in a page, or be sampled into SVG. This is possible because output targets consume the piece contract rather than the primitive that made it. Examples
References: src/…/core.ts• L1-6 src/types.ts• L63-70 examples/…/README.md• L1-18
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to the piece contract must remain compatible with browser playback, terminal playback, and SVG sampling.
- New composition sources must preserve their own options, colours, cell aspect, and timing when merged into a parent piece.
- New animated primitives must define deterministic frame behaviour and a usable loop or still point.
- New colour-producing primitives must fit the shared palette and light-page/dark-page model.
- New recipe words must stay aligned with the shared option vocabulary and the recipe entry points.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A frame uses unseeded or hidden state | Seeking, export, and reduced-motion output can differ from normal playback | Derive frames from t and seeded values |
| Combined periods do not meet within the supported loop range | The result has no reliable seamless loop for export | Set an explicit parent loop or choose compatible periods |
| Composition exceeds the maximum piece size | The new scene cannot be built | Reduce source sizes, spacing, or layer count |
| A scene combines too many distinct colours | Colours must be folded to the nearest available palette entry | Reuse palettes and keep the combined palette small |
| Text contains unsupported cell characters | The frame cannot represent the text as one character per cell | Use printable Basic Multilingual Plane characters |
Key files
| File | Why to read it |
|---|---|
| src/…/index.ts | Shows the public kit surface and how the primitive families relate. |
| src/…/core.ts | Defines the shared piece, surface, palette, ramp, and chaining model. |
| src/…/compose.ts | Explains how independent pieces become scenes and layouts. |
| src/…/index.ts | Shows the high-level recipe entry points. |
| src/…/draw.ts | Shows direct drawing on the shared cell surface. |
| src/…/field.ts | Shows procedural cell-by-cell scene generation. |
| src/…/fx.ts | Shows how visual changes wrap and return pieces. |
| src/…/particles.ts | Shows the time-based particle and simulation model. |
| src/…/shapes3d.ts | Shows the 3D scene source model. |
| src/…/materials.ts | Shows object, material, and emission-based scene assembly. |
| src/…/image.ts | Shows image-to-ASCII source conversion. |
| src/…/vector.ts | Shows SVG-to-ASCII conversion and animated SVG parts. |
| examples/…/README.md | Gives a product-level map of the kit's example scene types. |