Log inGet started
Package

canvas.module

README.md

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.