Kit geometry, math, and images
The kit turns geometry, time, and image data into pieces that can play in the same grid as text and other scene content. Its math layer keeps motion repeatable. Its vector and image layers bring external artwork into that model. Its 3D layer adds shapes, lighting, depth, and camera views without requiring each scene to manage its own projection.
Coordinate and time model
The geometry features use a small set of shared rules for position, scale, and time. These rules let a 2D drawing, a 3D scene, and an image behave as parts of one animated piece.
Vector spaces
The kit represents 2D points as [x, y] and 3D points as [x, y, z]. Grid coordinates use x across and y down. 3D coordinates use x right, y up, and z away from the camera. Vector operations return new points, so callers can combine positions and directions without changing the source values. src/…/math.ts• L835-895
The same coordinate model supports both direct drawing and 3D placement. Rotation, interpolation, distance, and projection provide the common language between a moving point and the cell where the point appears.
References: src/…/math.ts• L835-895 src/…/shapes3d.ts• L181-201
Deterministic math
The math layer provides repeatable values for patterns, placement, and motion. Seeded random values and noise return the same results for the same inputs. Time helpers express cycles, oscillation, pulses, and eased movement in seconds. This lets a piece rebuild any frame from its time rather than keep hidden state between frames. src/…/math.ts• L79-185
Noise can describe smooth, ridged, or cell-like patterns. It can drift, change in place, or return to its starting state after a period. Easing and tween helpers turn a time value into a controlled transition for numbers or points. src/…/math.ts• L344-365 src/…/math.ts• L467-492 src/…/math.ts• L765-832
References: src/…/math.ts• L79-185 src/…/math.ts• L344-365 src/…/math.ts• L467-492 src/…/math.ts• L765-832 src/…/math.ts• L1069-1155
Projection and camera
Projection maps a 3D point to a grid cell while retaining its distance from the viewer. A camera adds turning, tilt, perspective, and automatic fitting. The result gives callers both a screen position and a near-to-far value that can drive depth shading or occlusion choices. src/…/math.ts• L934-1055
The camera is the bridge between general 3D math and a piece. It keeps points inside the requested area when possible, while project() remains available when a caller needs direct control of the view.
References: src/…/math.ts• L934-1055
Vector scene inputs
Vector support treats an SVG as a source of named 2D shapes. The system converts those shapes to grid artwork, then lets the same parts move, change color, or receive a material inside a normal piece.
SVG geometry
parseSvg() reads SVG markup into a reusable drawing model. It preserves supported paths and basic shapes with their transforms, view box, fills, strokes, opacity, and group relationships. It also records addressable parts by id, class, or painted color. src/…/vector.ts• L60-110 src/…/vector.ts• L731-765
fromSvg() turns that model into a piece. The drawing can use logo, outline, block, or braille styles. drawSvg() uses the same model inside a larger piece, while svgPalette() supplies matching colors for that surrounding piece. src/…/vector.ts• L1166-1227 src/…/vector.ts• L2925-3061
The SVG boundary is deliberate. Text, embedded images, markers, masks, clip paths, and filters are not reproduced as full browser effects. Unsupported content is reported so a caller can choose a simpler source or convert text to paths before use.
References: src/…/vector.ts• L60-110 src/…/vector.ts• L711-729 src/…/vector.ts• L731-765 src/…/vector.ts• L1166-1227 src/…/vector.ts• L2925-3061
Part motion and fills
An SVG part is an addressable region that can have a built-in motion, a time-based pose, a color, a character, or a replacement fill. A part can also contain a material or another piece. This makes a still vector drawing usable as a small scene whose parts have separate roles. src/…/vector.ts• L972-998 src/…/vector.ts• L1094-1164
Part movement is expressed around an origin such as its center, a corner, or a custom point. When a part moves, its covered cells are recalculated so a fill continues to follow the shape. Materials therefore connect vector geometry to the material system described in kit effects and materials.
References: src/…/vector.ts• L972-998 src/…/vector.ts• L1034-1081 src/…/vector.ts• L1094-1164 src/…/vector.ts• L2963-3013
3D shape scenes
3D support describes a scene as shapes, their relationships, and the way a camera and light view them. The renderer resolves that description into a grid, where nearer surfaces win and brightness selects the visible character.
Shape families
The kit provides round, flat, line, point, and grouped shape families. Toruses, spheres, cubes, cylinders, cones, and planes cover common solid forms. Point clouds and paths support stars, galaxies, axes, or other sparse structures. Groups let nested objects move as one while their own motions continue. src/…/shapes3d.ts• L275-315 src/…/shapes3d.ts• L801-977
Every shape can have a position, initial rotation, scale, color, and motion. Surface shapes can also have a brightness texture and visible edges. Ready-made textures cover bands, stripes, checks, grids, and spots so a surface can gain visual identity without a separate pattern system. src/…/shapes3d.ts• L195-269
References: src/…/shapes3d.ts• L181-269 src/…/shapes3d.ts• L275-315 src/…/shapes3d.ts• L801-977
Scene rendering
scene() packages 3D shapes as a piece. render3d() places the same content into a piece that also draws text or other grid content. The view uses a camera, a light direction, an ambient level, a character ramp, and a color policy. Depth then decides which surface is visible in each cell. src/…/shapes3d.ts• L1174-1231 src/…/shapes3d.ts• L2122-2147
Scene timing is part of the visual contract. A declared period rounds spins and checks orbits so the first and last frame agree. scenePalette() exposes the scene colors for a larger piece, which keeps 3D output consistent with nearby text or artwork. src/…/shapes3d.ts• L2161-2187 src/…/shapes3d.ts• L2190-2219
The scene layer connects to kit scene composition when a 3D view must sit beside, above, or inside other pieces. It also uses the shared timing and rendering model described by creative coding kit.
References: src/…/shapes3d.ts• L1174-1231 src/…/shapes3d.ts• L1363-1378 src/…/shapes3d.ts• L2122-2219
Custom geometry
mesh() describes flat-faced forms from vertices and faces. parametric() describes a surface from two parameters and can make the surface change with time. These entry points extend the built-in shape families while keeping the same camera, light, texture, edge, and color rules. src/…/shapes3d.ts• L1030-1112
orbit() supplies a repeatable position for a moving shape. Combined with groups, it can express nested systems such as a moon around a planet that travels around a sun. The important contract is the shape description: scene timing must include each orbit's period when the scene is expected to loop. src/…/shapes3d.ts• L1149-1171
References: src/…/shapes3d.ts• L1030-1112 src/…/shapes3d.ts• L1149-1171 src/…/shapes3d.ts• L1369-1378
Mirroring and reversible views
Mirroring keeps flat artwork readable when a piece is flipped or shown from its reverse side. It changes both cell positions and characters when a character has a known visual mirror, while leaving characters without a safe mirror unchanged.
Character mirrors
The mirror table covers common pairs such as / and \\, parentheses, brackets, box drawing characters, directional symbols, half blocks, and braille dots. It provides separate left-right and top-bottom maps. src/…/mirror.ts• L8-33
The table is shared by composition flips and coin-like motion. This keeps a mirrored piece consistent whether the caller asks for a static horizontal or vertical flip or uses a motion recipe that reveals the back of a flat piece. src/…/compose.ts• L1130-1154 src/…/motion.ts• L107-155
References: src/…/mirror.ts• L8-33 src/…/compose.ts• L1130-1154 src/…/motion.ts• L107-155
Flat-piece motion
A flat piece that spins like a coin narrows toward an edge, then uses the character mirror for the back. This gives words and symbols a visual reverse without requiring a second source drawing. The result is a composition behavior, not a 3D surface: it is intended for banners, logos, and other already-rendered pieces. src/…/motion.ts• L107-155
References: src/…/motion.ts• L107-155 src/…/compose.ts• L1130-1154
Image conversion
Image support turns decoded pixels into a drawing that can stand alone or sit beside other grid content. The conversion keeps the source's main visual signal while adapting it to character cells and the page's color theme.
Image sources and pixels
fromImage() accepts browser image sources and Node PNG sources, then returns a normal piece. fromPixels() accepts RGBA data directly or compact rows of colored pixel characters. This separates image decoding from image-to-grid conversion, so a caller can use a different decoder and still share the same rendering behavior. src/…/image.ts• L119-126 src/…/image.ts• L1044-1065 src/…/image.ts• L1129-1150
The browser can use formats supported by its image APIs. In Node, the built-in path is PNG; other formats must first become pixels. A remote browser URL must allow access through CORS because the source is fetched in the page's context.
References: src/…/image.ts• L119-126 src/…/image.ts• L1044-1065 src/…/image.ts• L1129-1178
Conversion styles
The converter chooses a style based on the image's character. Logo style matches the shape of edges. Shade style maps brightness to a ramp and suits photos. Pixel style keeps small hard-edged artwork crisp by using half-cell pixels. A plain border can be removed so a logo does not become a block of background characters. src/…/image.ts• L24-85 src/…/image.ts• L238-264
Color output keeps up to a small set of representative colors. The system adjusts colors for light and dark pages so important marks remain visible. A glint is an optional time effect that crosses the image and makes the image piece loop at its chosen interval. src/…/image.ts• L661-804 src/…/image.ts• L906-965
References: src/…/image.ts• L24-85 src/…/image.ts• L238-389 src/…/image.ts• L392-458 src/…/image.ts• L661-804 src/…/image.ts• L906-965
Image composition
drawing() is the data form of a converted image. fromDrawing() makes it playable, while drawImage() places it into a surface without replacing the surrounding content. imagePalette() lets the containing piece reserve the image's colors instead of approximating them with a nearby palette entry. src/…/image.ts• L87-117 src/…/image.ts• L937-965 src/…/image.ts• L981-1041
This makes an image a peer of text, fields, particles, and effects. Use kit drawing and fields for other grid primitives, kit particles and simulation for moving point systems, and kit effects and materials for effects that wrap or fill the resulting piece.
References: src/…/image.ts• L87-117 src/…/image.ts• L937-965 src/…/image.ts• L981-1041
Kit relationships
These geometry and image features form the visual foundation for the wider kit:
- Creative coding kit explains the common piece and time model.
- Kit scene composition explains how these pieces are arranged into larger outputs.
- Kit drawing and fields covers direct grid drawing and formula-driven fields.
- Kit effects and materials covers fills, materials, and effects applied to these outputs.
- Kit particles and simulation covers time-based systems that can be composed beside them.
- Kit recipes covers named higher-level scenes and motions built from these foundations.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep
scenePalette()andrender3d()options aligned so embedded 3D scenes use the same colors and shading as standalone scenes. - Keep
parseSvg()support andfromSvg()'s documented skipped content aligned so callers know which artwork survives conversion. - Keep vector part selectors and their motion or material plans aligned with the shape names exposed by
parseSvg().parts. - Keep
fromImage(),fromPixels(),drawing(), anddrawImage()consistent about image styles, color limits, and theme palettes. - Keep mirror mappings aligned with every composition or motion path that claims to show a reversed piece.
- Keep declared periods aligned with orbit, spin, glint, noise, and tween sources so looping output has no jump.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An SVG uses text, images, masks, filters, or clip paths as required visual content | The converted piece omits or simplifies that content | Check parseSvg().skipped and convert important text to paths before calling fromSvg() |
| A 3D scene declares a period that is not a whole number of orbit cycles | The scene can jump when it loops | Choose a period that contains whole orbit turns or leave the period to the scene's loop calculation |
| An image source is a remote browser URL without CORS access | fromImage() cannot fetch or decode the source | Use a same-origin source, enable CORS, or pass decoded pixels to fromPixels() |
| A piece combines image or 3D colors beyond the piece palette limit | Palette creation fails or the source colors cannot be preserved | Reduce source colors or reserve a smaller shared palette with imagePalette() or scenePalette() |
| A vector part selector matches no SVG part | The requested motion or fill cannot be applied | Use parseSvg().parts to verify ids, classes, or color selectors |
Key files
| File | Why to read it |
|---|---|
| src/…/index.ts | Public export map for math, 3D scenes, images, mirroring-related composition, and SVG support |
| src/…/math.ts | Shared coordinate, deterministic time, noise, vector, projection, and camera model |
| src/…/vector.ts | SVG parsing, part addressing, vector styles, part motion, fills, and embedded drawing |
| src/…/shapes3d.ts | Shape descriptions, custom geometry, orbits, camera and light settings, and 3D rendering |
| src/…/image.ts | Image source decoding, pixel conversion, drawings, palettes, glints, and embedded image drawing |
| src/…/mirror.ts | Shared character maps for horizontal and vertical mirroring |
| src/…/compose.ts | Public piece flipping behavior that applies the mirror maps to cells and characters |
| src/…/motion.ts | Coin-like motion that shows a flat piece's mirrored back |