# design
What a mural is meant to be: a grid of cells, each belonging to a pigment or to none.
```
A design is authored as rows of characters with a legend, small enough to write by hand, and scaled up to a
canvas by repeating cells. Row 1 of the text is the TOP of the mural; in the design, row index 1 is the bottom
(v grows upward, like the wall).
local Design = require("~.modules.design")
local d = Design.fromRows({
rows = { ".oo.",
"otto",
".oo." },
legend = { o = "ochre", t = "teal" }, -- any character not in the legend is empty
scale = 4, -- each character becomes 4 x 4 cells (default 1)
})
d.cols, d.rows, d.pigments = { "ochre", "teal" } -- pigments sorted by name
d.cells[(row - 1) * d.cols + col] -- pigment index (1..) or 0 for none
Design.count(d) -- { total, byPigment = { ochre = n, teal = n }, edge = n }
Design.tins(d, cellSize, tinPer) -- { ochre = 0.8, teal = 0.2 } tins to fill it once at `tinPer` m2 per tin
Design.isEdge(d, col, row) -- a design cell with a neighbour of another pigment or none
Design.size(d, cellSize) -- width, height in metres
```
The interface is documented in the header of `init.luau`; this file repeats it for the asset browser.
# engineAdapters
The engine side: splats as decal projectors, and the physics query the
```
ballistics need.
The rest of paintKit is engine-free and is what the test suite covers. This is the only module that calls the
engine. NOT YET RUN IN THE ENGINE (2026-11-19). It uses what the builtin decals module documents:
`decals.set(entityId, { material, opacity })` on an entity whose Transform is the projection box (position,
rotation orienting local -Z along the projection, scale as the box size), and `decals.clear(entityId)`.
local Adapters = require("~.modules.engineAdapters")
local view = Adapters.splatView({
material = function(pigment) return materialRefFor(pigment) end, -- one material per pigment (required)
depth = 0.4, -- how deep the box projects into the surface (metres)
opacity = 1,
parent = nil, -- entity id the projector entities are parented to (optional)
entityOf = function(target) return entityId end, -- for splats ON things: the thing's entity (the
-- projector is parented to it and placed in its local space)
})
view:sync(store:drain()) -- call after anything changed: spawns, resizes and removes projectors
view:clear() -- remove every projector it made
local query = Adapters.query({
classify = function(entityId, hit) return kind, target, part end, -- what an entity is to the game
entityOf = function(target) return entityId end, -- the firer's entity (to exclude it)
things = function(centre, radius) return { { target, kind, part, x, y, z } } end, -- for splash and cones
}) -- the query modules/ballistics and modules/impact take, on Physics.raycast
To confirm on first run: the decals README says a projector stamps along its local -Z, while its own example
rotates +90 degrees about X to "project down" (which turns local +Z down). `facing` below follows the README;
if splats come out faded or on the wrong face, negate the direction passed to it in `place`.
Projectors are batched by the engine eight to a pass per material, so the number of pigments, not the number
of splats, sets the pass count; the store's `max` is the budget.
```
The interface is documented in the header of `init.luau`; this file repeats it for the asset browser.
# canvas
A paintable surface with a design: strokes, completion, quality, signing, scrubbing.
```
A canvas is a grid of cells (cfg.cell metres) lying on a wall: u runs along it from its left edge, v up from its
foot. Each cell holds how full it is (0..1) and which pigment is on it. A stroke fills the cells whose centres
lie in its mark. The design says which pigment each cell should have; quality compares the two.
local Canvas = require("~.modules.canvas")
local c = Canvas.new(cfg, design) -- cfg: paintKit config; design: design.module
local r = c:stroke({ u = 1.0, v = 1.2, radius = 0.16, pigment = "ochre", amount = 0.4,
spill = 0, maxV = 2.6, mask = nil })
-- r = { touched, added } cells touched and fill added (in cells). `mask = "teal"` paints only cells whose
-- design pigment is teal (a stencil); `maxV` leaves cells above that height untouched (reach).
local q = c:quality()
-- q = { coverage, accuracy, overspray, tier ("masterwork" | ... | nil), score (0..1), painted (share of all
-- design cells with any paint), byPigment = { ochre = { need, done } } }
c:sign() -- fixes the tier (returns it; nil if below the lowest tier: nothing is signed)
c.signed, c.tier
c:scrub(0.1) -- removes that share of the design's cells' paint, top row first; returns the share left
c.state -- "blank" | "started" | "signed" | "scrubbed"
c:cellAt(u, v) -- col, row (or nil outside) c:centre(col, row) -- u, v
c:nextGap(pigment?) -- u, v of the lowest unfinished design cell (of that pigment), for guidance
local text = c:serialise() Canvas.restore(cfg, design, text)
Painting a different pigment over a cell keeps cfg.repaint.keep of its fill and changes its pigment, so going
over a mistake costs a second coat.
```
The interface is documented in the header of `init.luau`; this file repeats it for the asset browser.
# painter
A painter's hands: the tool and pigment in use, and what one tick of painting does.
```
It joins a supply, the tool table and a canvas (paint thrown at things is modules/arms). It knows nothing about input, cameras or characters: the host
says where on the canvas the tool points and how far away the painter stands.
local Painter = require("~.modules.painter")
local p = Painter.new(cfg, supply, { tools = { "spray" } }) -- the tools owned (names in cfg.tools)
p:own("roller") p:selectTool("roller") p:cycleTool(1)
p:selectPigment("ochre") p:cyclePigment(1) -- among pigments the supply holds
local r = p:paint(canvas, dt, { u = 1.2, v = 0.9, distance = 1.4, stand = 0, stencil = nil })
-- call every tick while the trigger is held
-- r = { ok = true, used = tins, added = cells, touched = cells, loudness = n }
-- | { ok = false, reason = "no tool" | "no pigment" | "empty" | "too far" | "out of reach" | "signed" }
-- `stand` is how high the painter's feet are above the canvas's foot (a ladder, a van roof).
-- `stencil = "teal"` with a tool whose config says masked = true paints only the teal region.
p:loudness() -- the selected tool's loudness (0 with no tool), for whatever is watching
p.tool, p.pigment
```
The interface is documented in the header of `init.luau`; this file repeats it for the asset browser.
# config
Paint tools, paint arms, pigments, cover, colour and surface effects as one data table.
```
paintKit holds no numbers of its own. `Config.DEFAULTS` is a complete neutral set; a game overrides it:
local Config = require("~.modules.config")
local cfg = Config.merge(Config.DEFAULTS, { tools = { spray = { coverage = 1 } } })
local ok, problems = Config.validate(cfg)
Schema (the module that reads each part is in brackets):
cell metres per canvas cell (the grain of every mural) [canvas]
tools[name] = { what paints a canvas [painter]
mode = "stream" paints while held
radius metres of the mark on the surface
coverage square metres per second
tinPer square metres one tin covers
reach metres above the painter's feet the tool reaches
range metres from the surface it works at
spill 0..1: extra radius, as a share, painted at half strength (sloppy edges)
loudness how visible using it is (the game feeds this to whatever watches)
masked = true paints only the cells of the region it was prepared for (a stencil)
}
arms[name] = { what fires paint at things [arms]
mode = "pellet" | "lob" | "stream" | "cone"
pellet: `pellets` projectiles a shot, flying flat and fast; lob: one heavy projectile on a high arc
that bursts over `splash` metres; stream: droplets while held; cone: no projectile, everything in a
short cone gets `cover` per second (a spray can in a face)
pellets, spread projectiles a shot, and the half-angle of their scatter in degrees
speed, gravity, range metres a second at the muzzle, m/s2 pulling down, metres before it is spent
radius metres of the mark one projectile leaves
cover cover one projectile adds to what it hits (cone: per second)
splash metres round the impact that also take cover and marks (lob)
shotsPerTin shots one tin gives (stream and cone: seconds of fire a tin gives)
interval seconds between shots (stream: between droplets)
halfAngle cone only: half-angle in degrees
loudness, heard how visible firing it is, and how far away its report is heard (metres)
mount nil = carried; a name = only usable from that mount (the host says which)
scope zoom factor when aimed (nil = none)
}
ballistics = { step, maxShots } longest sub-step in seconds; projectiles alive at once [ballistics]
pigments[id] = { tactical properties; a pigment with no entry is plain [pigments]
cover multiplies the cover a hit adds (default 1)
blind multiplies the seconds of any "blind" effect it causes (default 1)
fade multiplies how long its marks last where marks fade (default 1)
effects = { { effect, on = { kind, ... }, seconds?, radius?, factor? } }
extra effects when it lands on a thing of one of those kinds
}
cover = { kinds[kind] = { what can be painted out [cover]
parts[part] = { capacity, effects = { { at, effect, seconds?, offence? } } }
capacity: cover that fills the part (1 = one full-strength hit);
effects fire when the part's cover rises through `at` (0..1)
defaultPart the part a hit lands on when the host names none
out = { part?, at, seconds?, effect?, offence? }
painted out when `part` (or, with no part, the mean of all parts) reaches
`at`; for `seconds` (nil: until repaired)
wipe = { after, rate } parts lose `rate` cover a second once `after` seconds pass without a hit
persist = true kept in a save (fixed things: lenses, relays)
} }
colour = { the painter's own colour, stripped by solvent [colour]
recover = { delay, rate, friendly } seconds unseen before it returns, share per second, and the extra
factor at full `friendly` ground (rate * (1 + friendly * ground))
edges the colour below which the picture starts to drain (for the screen)
washedOut = { reviveAt, speed, canPaint, canFire, grabWindow }
at zero colour the painter is washed out until colour is back to reviveAt:
speed factor, what the hands can do, and the factor on a pursuer's grab window
}
quality = { fillAt, overAt, tiers = { { name, coverage, accuracy?, overspray? } best first } } [canvas]
repaint = { keep } painting a different pigment over a cell keeps this share of its fill [canvas]
scrub = { gone } a canvas whose painted share falls below this is "scrubbed" [canvas]
surfaces[kind][arm|tool|"any"] = { effect, seconds?, radius?, offence? } [surfaces, impact]
what paint does to plain surfaces ("mark" leaves a splat)
splats = { max, bucket, mergeWithin, maxRadius, maxPerTarget,
rules[surface] = { life?, scrub? } } life: seconds a mark lasts there (nil: until scrubbed) [splats]
```
The interface is documented in the header of `init.luau`; this file repeats it for the asset browser.
# supply
Paint you can carry: tins by pigment, a capacity, a limit on pigments loaded at once.
```
The same object is a satchel, a vehicle's shelf, a stash in a doorway or a shop's stock; only the numbers differ.
Tins are fractional while in use (a stream draws 0.02 of a tin a frame) and whole when counted for a player.
local Supply = require("~.modules.supply")
local bag = Supply.new({ capacity = 12, slots = 3 }) -- slots: how many different pigments at once (nil = any)
bag:add("ochre", 6) -- returns how many were accepted (capacity and slots are respected)
bag:take("ochre", 0.25) -- returns how much was really taken
bag:count("ochre") bag:total() bag:room() bag:pigments() -- pigments: names with paint, sorted
bag:transfer(van, "ochre", 4) -- returns how many moved (limited by what is here and the room there)
local taken = bag:empty() -- { ochre = 5.5, ... } and the bag is empty (a confiscation)
bag:setLimits({ capacity = 20 })
local data = bag:serialise() Supply.restore(data) -- plain tables for a save
```
The interface is documented in the header of `init.luau`; this file repeats it for the asset browser.
# splats
The marks paint leaves, on the world and on things that move, within a budget.
```
A splat is a position, a surface normal, a radius and a pigment. It sits either on the world (x, y, z in world
metres) or on a thing (`target` = the thing's id, x, y, z in the thing's own space, so it travels with a car
or a person). The store keeps at most cfg.splats.max of them (the oldest goes first) and at most
cfg.splats.maxPerTarget on one thing, merges a new mark into a near one of the same pigment instead of
stacking, finds world marks near a point through a grid, ages the marks whose surface says they fade
(cfg.splats.rules[surface].life), and reports what changed since it was last asked so a renderer keeps up
without rescanning.
local Splats = require("~.modules.splats")
local store = Splats.new(cfg.splats)
local id, merged = store:add({ x, y, z, nx, ny, nz, radius = 0.4, pigment = "ochre", surface = "wall" })
store:add({ target = "car12", x = 0.2, y = 1.1, z = 1.9, radius = 0.3, pigment = "white", surface = "glass" })
-- (a second argument `true` adds without merging; spec.life overrides the surface rule's life)
store:near(x, z, 5) -- world splats within 5 m on the ground plane, nearest first
store:on("car12") -- the splats on a thing, oldest first
store:get(id) store:remove(id) store:count()
store:removeNear(x, z, r) -- scrubbed away; returns how many (only where the surface allows scrubbing)
store:removeOn("car12") -- washed; returns how many
store:tick(dt) -- ages fading marks; returns how many went
local delta = store:drain() -- { added = { splat }, changed = { splat }, removed = { id } } since last drain
local data = store:serialise() -- world splats as compact rows (centimetres), oldest first
Splats.restore(cfg.splats, data)
store:serialiseOn("car12") store:restoreOn("car12", rows) -- a thing's marks, to keep with the thing
```
The interface is documented in the header of `init.luau`; this file repeats it for the asset browser.
# surfaces
What paint does to the thing it lands on, and for how long.
```
Paint on a wall is a mark. Paint on a lens, a windscreen, a road or a person may be an effect with a duration.
Which is data: cfg.surfaces[kind][tool] (or [kind].any) = { effect, seconds?, radius?, offence? }. This module
looks the rule up and keeps the timed effects that are running, including ones that cover an area.
local Surfaces = require("~.modules.surfaces")
local rule = Surfaces.rule(cfg.surfaces, "lens", "spray") -- { effect = "blind", ... } or nil
local field = Surfaces.field()
field:apply("cam12", rule) -- start (or restart) a timed effect on a thing
field:applyAt("slick7", rule, x, z) -- an effect that covers rule.radius round a point
field:has("cam12", "blind") field:left("cam12", "blind") -- seconds left (0 when not active)
field:at(x, z, "slick") -- the id of an area effect covering that point, or nil
field:clear("cam12", "blind") -- repaired / cleaned (returns true if it was active)
local ended = field:tick(dt) -- { { id, effect } } that ran out this tick
field:serialise() Surfaces.restore(data)
An effect with no `seconds` lasts until cleared.
```
The interface is documented in the header of `init.luau`; this file repeats it for the asset browser.
# paintKit
Paint as a game system: what you carry, what the tools do, what a mural is meant to be and how well it was done;
and paint as a weapon: arms that fire pigment as real projectiles, cover as the health of everything paintable,
"painted out" instead of dead, the painter's own colour stripped by solvent, and marks that stay on walls, cars
and people. Engine-free logic configured by data; nothing in it names a game.
**Status (2026-11-22): logic run in the engine through `caseBench` (62 cases pass). `engineAdapters` (decal
splats, the `Physics.raycast` query) is written against the documented API and has NOT been run in a scene.**
## What is in it
| Module (`require("paintKit.modules.<name>")`) | What it does | Engine calls |
|-|-|-|
| `config` | `DEFAULTS`, `merge` (with `NONE` to drop a default), `validate`: the whole kit as one table | none |
| `supply` | tins by pigment with a capacity and pigment slots: a satchel, a shelf, a stash | none |
| `design` | a mural's intended picture from rows of characters and a legend, scaled to cells | none |
| `canvas` | cells with fill and pigment: `stroke`, `quality`, `sign`, `scrub`, `nextGap`, `serialise` / `restore` | none |
| `painter` | tool and pigment in hand; one tick of painting a canvas, with reasons for refusal | none |
| `arms` | paint arms: owned, selected, cadence, paint per shot; builds a shot's projectiles (seeded scatter) or a cone pulse | none |
| `ballistics` | projectiles under gravity in fixed sub-steps, hits through an injected query; `cone`, `splash`, `arc`, `lobVelocity`, `lead` | none |
| `pigments` | tactical properties of pigments: cover / blind / fade factors and extra effects by target kind | none |
| `cover` | cover per part of a thing, threshold effects, painted out and back, wiping, repair, save of fixed things | none |
| `colour` | the painter's own colour: `wash`, washed out, recovery unseen and on friendly ground, `effects` | none |
| `impact` | what a hit does: cover or a mark, surface rule, pigment effects, splash; reports offences | none |
| `splats` | marks on the world and on moving things: merge, budgets, fading, spatial lookup, change feed, save | none |
| `surfaces` | rule lookup for paint on a kind of surface; a field of timed and area effects | none |
| `engineAdapters` | `splatView` (decal projectors, also parented to things), `query` (the ballistics query on `Physics.raycast`) | `entity.spawn`, `@builtin::modules.decals`, `Physics.raycast` |
`tests/cases/core` (canvas, supply, painter, splats, surfaces) and `tests/cases/arms` (arms, ballistics, cover,
colour, pigments, impact, splats on things): 62 cases of pure logic. `tests/paintKit.testSuite` hands the same
cases to the engine's framework.
## Config schema
The header of `modules/config` is the schema. In short:
```lua
{
cell = 0.25,
tools = { spray = { mode = "stream", radius, coverage, tinPer, reach, range, spill, loudness, masked? } },
arms = { pistol = { mode = "pellet" | "lob" | "stream" | "cone", pellets, spread, speed, gravity, range, radius,
cover, splash?, shotsPerTin, interval, halfAngle?, loudness, heard, mount?, scope? } },
ballistics = { step, maxShots },
pigments = { white = { cover?, blind?, fade?, effects = { { effect, on = { kind }, seconds?, radius?, factor? } } } },
cover = { kinds = { guard = { parts = { visor = { capacity, effects = { { at, effect, seconds?, offence? } } } },
defaultPart, out = { part?, at, seconds?, effect?, offence? }, wipe?, persist? } } },
colour = { recover = { delay, rate, friendly }, edges, washedOut = { reviveAt, speed, canPaint, canFire, grabWindow } },
quality = { fillAt, overAt, tiers = { { name, coverage, accuracy?, overspray? }, ... } },
repaint = { keep }, scrub = { gone },
surfaces = { [kind] = { [arm | tool] | any = { effect, seconds?, radius?, offence? } } },
splats = { max, bucket, mergeWithin, maxRadius, maxPerTarget, rules = { [surface] = { life?, scrub? } } },
}
```
## Using it: a mural
```lua
local Config = require("paintKit.modules.config")
local Supply = require("paintKit.modules.supply")
local Design = require("paintKit.modules.design")
local Canvas = require("paintKit.modules.canvas")
local Painter = require("paintKit.modules.painter")
local cfg = Config.merge(Config.DEFAULTS, myPaintConfig)
local bag = Supply.new({ capacity = 12, slots = 3 }); bag:add("ochre", 6)
local hand = Painter.new(cfg, bag, { tools = { "spray" } })
local wall = Canvas.new(cfg, Design.fromRows({ rows = { ".oo.", "oooo" }, legend = { o = "ochre" }, scale = 4 }))
local r = hand:paint(wall, dt, { u = u, v = v, distance = d, stand = feetAboveWallFoot })
if not r.ok then hud.say(r.reason) end -- "empty", "too far", "out of reach", "signed", ...
local tier = wall:sign() -- fixes it; nil if below the lowest tier
```
## Using it: a firefight
```lua
local Arms = require("paintKit.modules.arms")
local Ballistics = require("paintKit.modules.ballistics")
local Cover = require("paintKit.modules.cover")
local Splats = require("paintKit.modules.splats")
local Surfaces = require("paintKit.modules.surfaces")
local Impact = require("paintKit.modules.impact")
local arms = Arms.new(cfg, bag, { arms = { "pistol" }, rng = seededRng }) -- same tins as the murals
local air = Ballistics.new(cfg.ballistics, query) -- query: see below
local cover, splats, field = Cover.new(cfg.cover), Splats.new(cfg.splats), Surfaces.field()
local impact = Impact.new(cfg, { cover = cover, splats = splats, field = field, query = query })
-- trigger pulled
local fired = arms:fire({ origin = muzzle, dir = aimDirection, owner = "player" })
if fired.ok then
for _, shot in fired.shots or {} do air:spawn(shot) end
if fired.cone then for _, report in impact:pulse(fired.cone) do handle(report) end end
witnesses.heard(fired.heard, fired.loudness)
end
-- every tick
arms:tick(dt)
for _, e in air:step(dt) do
if e.type == "impact" then
local report = impact:land(e.shot, e.hit) -- cover, mark, effects, offences, splash
for _, c in report.cover do
if c.type == "out" then guards.paintedOut(c.id, c.seconds) end
if c.type == "effect" and c.effect == "blind" then guards.blind(c.id, c.seconds) end
end
for _, offence in report.offences do crimes.report(offence) end
end
end
for _, e in cover:tick(dt) do guards.back(e.id) end
splats:tick(dt); view:sync(splats:drain())
```
Solvent coming the other way is the same machinery with a different consequence: the host flies the pursuers'
shots through its own `Ballistics`, and a hit on the painter calls `colour:wash(amount)`;
`colour:effects()` then says how slow the painter is and whether the hands still work.
## Interfaces the host provides
- **Physics query** (for `ballistics` and `impact`):
`query.raycast(origin, dir, distance, exclude) -> { x, y, z, nx, ny, nz, distance, kind, target?, part?, lx?, ly?, lz? } | nil`
and, for splash and cone arms, `query.overlap(centre, radius) -> { { target, kind, part?, x, y, z } }`.
`kind` is a surface kind (`cfg.surfaces`) or a cover kind (`cfg.cover.kinds`); `target` is the id of a thing.
`engineAdapters.query{ classify, entityOf, things }` builds it on `Physics.raycast`.
- **A seeded generator** `rng() -> [0, 1)` for scatter (the kit ships none, so every random number is the host's).
- **Where a tool points on a canvas**: `(u, v)` in metres from its lower-left corner, the painter's distance and
the height of its feet above the wall's foot.
- **Drawing**: canvases, shots in flight (`air:each`), splats (`store:drain()`; `engineAdapters.splatView`), cover
meters (`cover:view(id)`), the screen draining with `colour:effects().drain`.
## Events
paintKit returns results instead of emitting events: every call that changes something returns what changed
(`fire` → shots or a cone, `step` → impacts and spent shots, `land` / `pulse` → reports, `hit` → cover events,
`tick` → things back, `wash` → value and washed out, `stroke` → touched and added, `sign` → tier, `Field:tick` →
ended effects, `Splats:drain` → added / changed / removed). The host turns those into its own events.
## Example config for a pump gun and a blinding pigment
```lua
local cfg = Config.merge(Config.DEFAULTS, {
arms = { scatter = { mode = "pellet", pellets = 8, spread = 7, speed = 45, gravity = 9.8, range = 12,
radius = 0.14, cover = 0.14, shotsPerTin = 4, interval = 0.9, loudness = 2.5, heard = 60 } },
pigments = { white = { blind = 1.75 } },
})
```