Kit effects and materials
The kit turns a source piece into changing visual output and turns a named surface into a scene part. Effects change the frames of an existing piece over time. Materials give an area its surface, depth, colour, and motion. Together they let a scene show both whole-piece changes and local surface changes. The result remains a normal piece that can play in the rest of the kit. See the creative coding kit for the wider model and scene composition for the part and layer flow.
Visual-effect pipeline
An effect wraps a piece, text block, or grid and returns another piece. The wrapper reads the source frame at the current time, applies one visual change, and keeps the result usable by players, layouts, SVG output, and terminal output.
flowchart LR
A[Piece, text, or grid] --> B[Source frame]
B --> C[Effect transform]
C --> D[New frame]
D --> E[Normal piece]
E --> F[Player, layout, SVG, or terminal]
Source handling
Effects accept the same broad source types as the kit's other piece tools. Text and grids become still or animated sources, while an existing piece keeps its size, theme colours, options, and motion contract unless the effect changes them.
An effect can pass source options through its own options. This lets a wrapper control a source feature without changing the source object itself. For example, a logo can keep its own shine still while a new glint supplies the visible shine.
References: src/…/fx.ts• L58-71 src/…/fx.ts• L331-343 src/…/fx.ts• L368-410
Frame transformation
The built-in effects cover several kinds of visual change. Some change ink or colour. Others reveal, hide, distort, move, or add a border around the source. Effects that need more room grow the output so the source is not cut off.
| Effect group | Examples | Visual role |
|---|---|---|
| Light and colour | glint(), rainbow(), hueCycle() | Add a moving highlight or recolour the source. |
| Reveal and loss | typeIn(), dissolve(), fade(), scan() | Control how much of the source is visible. |
| Motion and damage | wave(), shake(), glitch() | Move rows or cells and add short bursts of change. |
| Shape treatment | outline(), shadow() | Add a border or a cast shadow around the source. |
The source is copied back unchanged when a transient effect is inactive. This keeps the effect as a layer over the source rather than a second unrelated drawing.
References: src/…/fx.ts• L502-611 src/…/fx.ts• L714-930 src/…/fx.ts• L933-1197 src/…/fx.ts• L1200-1375
Effect chaining
Chaining passes each result to the next effect. The order matters because a later effect sees the frame made by the earlier one. This supports combinations such as typing a title, outlining it, and then adding a shadow.
Every chained result is still a piece. It can therefore receive more kit steps or move into a layout without a special adapter. The chain also combines the source and effect timing rules so the final piece can report a usable loop when the periods meet within the kit's time limit.
References: src/…/fx.ts• L1461-1477 src/…/fx.ts• L368-461
Material model
A material describes how an area looks and how that look changes. The area supplies the place and boundary. The material supplies the characters, colours, transparency, depth cues, and local motion. This separates scene meaning from surface treatment.
Area and shape roles
An area answers “where is this thing?” It can be a named object, a fixed region, a custom outline, or a combination of regions. A shape turns that area into a scene part by filling it with a material. If no material is given, a shape can use its own natural surface, such as glass for a cup or fire for a flame.
Placement words keep the scene stable as its size changes. Areas can sit within another area, stand on it, or expose named points for related parts. This is why a liquid can stay inside a vessel and an emission can leave from a chimney without hand-built cell coordinates.
References: src/…/materials.ts• L176-243 src/…/materials.ts• L639-722 src/…/materials.ts• L3076-3143
Surface treatment
Materials range from simple fills to surfaces that show depth or what is below them. A transparent material reads the earlier scene layer before it draws. A shaded material uses the area's edge and depth so the same surface reads in colour and in one ink.
| Surface need | Material examples | Result |
|---|---|---|
| Flat or shaded fill | solid(), gradientFill(), pattern() | A stable fill with a chosen character, ramp, fade, or tile. |
| Physical surface | water(), glass(), metal(), ceramic(), wood(), ice() | A surface with depth, edges, transparency, or highlights. |
| Living or glowing surface | fire(), lava(), neon(), grass(), starfield() | A local motion or light change inside the area. |
| Embedded piece | texture(piece) | Another piece plays inside an area as a screen or sign. |
Materials use named colour sets or user colours for both light and dark pages. The scene gathers those colours into one palette, while one-ink output uses characters and shading to preserve the main visual difference.
References: src/…/materials.ts• L1279-1331 src/…/materials.ts• L1383-1480 src/…/materials.ts• L1482-1588 src/…/materials.ts• L2140-2255 src/…/materials.ts• L2909-2955
Emission behavior
An emission describes things released from a source or living inside a region. Bubbles rise within a liquid. Smoke and steam rise from an area. Rain, snow, and sparks move through the scene. An emission is added with emit() rather than used as a surface fill.
The emission receives a source point or area and a movement limit. This keeps particles tied to the scene object that produces them and keeps bounded particles inside their target area. Built-in emissions and custom emissions use the same high-level contract: a time value determines each live particle's position and appearance.
References: src/…/materials.ts• L2409-2440 src/…/materials.ts• L2463-2568 src/…/materials.ts• L2570-2866 src/…/materials.ts• L3145-3192
Scene assembly and timing
The material system and effect system meet at the piece boundary. A picture draws its parts in order. An effect can then wrap the finished picture, or a material can place another piece inside one area. This allows scene-level and surface-level change to remain separate.
Layer and color assembly
Parts draw from back to front. Each part can read the current layer before it draws, so glass, water, ice, and other see-through surfaces can preserve selected marks from below. A later opaque surface can replace those cells.
The picture builds its colour set from its parts. It keeps separate light-page and dark-page values and maps each material to its own colour range. drawParts() provides the same ordered part drawing when a custom piece() needs to add labels or other drawing around the material scene.
References: src/…/materials.ts• L1284-1298 src/…/materials.ts• L3227-3255 src/…/materials.ts• L3257-3319 src/…/materials.ts• L3323-3357
Time behavior
Material motion, shape motion, emissions, and effects each contribute a time period. A picture combines the periods when it can find a shared repeat within one minute. A source or custom motion that never repeats still plays, but the final piece has no fixed loop.
The frame depends on the requested time rather than on past frames. This makes the same scene safe to sample for SVG, reduced motion, terminal playback, or a player that draws frames out of order. Effects use the same rule and select a still point for reduced-motion playback.
References: src/…/materials.ts• L1300-1319 src/…/materials.ts• L3195-3209 src/…/materials.ts• L3323-3357 src/…/fx.ts• L264-284 src/…/fx.ts• L443-461
Extension points
The abstractions support new surface treatments and new frame transforms without changing the piece contract. Custom code supplies a small drawing rule while the kit still owns placement, colour mapping, timing, and output size.
Custom materials
material() defines a surface from a cell and a time value. The cell describes its position within the area and its distance from the edge. The drawing can return a character, a character with a colour index, or no mark. A period makes time-based material motion repeat; without one, time-based motion remains open-ended.
References: src/…/materials.ts• L2326-2391
Custom effects
effect() defines a transform over a source frame. The drawing can copy the source, add marks, move content, or read another source time for an echo or trail. A custom effect can set its own period, still frame, extra room, and colours while returning the same normal piece type as the built-ins.
Custom particle behavior belongs to emission(), which is useful when the change is a stream of independent items rather than a treatment of every cell. For formula-driven images, see drawing and fields. For larger particle systems, see particles and simulation.
References: src/…/materials.ts• L2767-2866 src/…/fx.ts• L1377-1458
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the distinction between a surface material, an emission, and a piece effect. They are attached at different points in the scene flow.
- When a material adds or changes colour roles, check the shared light and dark palette budget used by
picture()anddrawParts(). - When a material or effect gains time-based behavior, check its period, still frame, and the final picture loop together.
- When a transparent material changes its layer read, check the order of the parts that it is meant to show through.
- When a moving shape changes its bounds, check that its frame still has room for the full motion and that the scene does not clip it.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A picture combines more than its supported per-page colour set | Picture creation fails instead of silently changing colours | Reuse colour pairs or set shared material colours. |
| A material or emission uses a time value without a repeat period | The piece plays but has no fixed loop | Give repeating time-based custom work an explicit period. |
An emission is passed to shape() | The scene rejects the part because emissions are not surface fills | Attach it with emit() and give its source or bounds. |
| A transparent material is drawn in the wrong layer order | The material cannot show the intended background or highlight | Draw the background and source object before the transparent part. |
| An effect grows a source beyond the piece size limit | Effect creation fails because the new frame cannot fit | Reduce the effect reach or use a smaller source. |
Key files
| File | Why to read it |
|---|---|
| src/…/materials.ts | Defines areas, materials, emissions, parts, pictures, palette assembly, and the material-to-frame flow. |
| src/…/fx.ts | Defines the source-to-effect pipeline, built-in effects, custom effects, chaining, and timing rules. |
| src/…/index.ts | Shows the public kit surface for effects, materials, emissions, and scene composition. |
| src/…/materials.test.ts | Shows the visual contracts for transparency, depth, motion, emissions, palettes, and composed pictures. |
| src/…/fx.test.ts | Shows the frame, colour, loop, size, chaining, and reduced-motion contracts for effects. |
| kit-scene-composition.md | Explains how these parts are placed and layered into a scene. |
| kit-drawing-and-fields.md | Covers direct grid drawing and formula-based visuals that can sit beside these abstractions. |
| kit-particles-and-simulation.md | Covers particle systems when emissions are not enough for the scene. |