A small surface for a diagram's strokes: one band of pixels, as tall as a text row and as wide as the diagram, drawn and written out, then reused for the next row.
A caller draws in the diagram's own pixel coordinates. The band clips what falls outside its rows, so one list of shapes serves every band.
Two kinds of drawing cover a diagram. A rectangle of whole pixels is copied in: a line along a cell row or column needs no smoothing. Any other shape is given as a coverage function, called once for each pixel centre in its bounding box; a distance to the shape's edge turns into a soft edge there.
A band holds premultiplied colour and writes straight RGBA, 8 bits a
channel, which is the Kitty graphics protocol's f=32.
| Name | Signature |
|---|---|
| new | new(width, height) -> band |
new(
width,height) ->band
Make a band of pixels
A band is width by height pixels and starts clear. An ink is
{ r, g, b, a }, each from 0 to 1, with straight alpha. A box is
x0, y0, x1, y1 in whole pixels of the diagram, the last column and row
left out.
| Method | Does |
|---|---|
clear(top) | clears the band and moves it to start at the diagram's row top |
rect(x0, y0, x1, y1, ink, dash) | lays ink over a box |
shade(x0, y0, x1, y1, coverage, ink) | lays ink over the box's pixels by coverage(x, y), called at each pixel's centre and answering 0 to 1 |
erase(x0, y0, x1, y1) | clears a box |
serialise() | returns the band as RGBA bytes, width * height * 4 of them, or nil when it holds no ink |
dash is { axis, on, period }: along axis, "x" or "y", the ink
is laid where the diagram's pixel coordinate modulo period is under
on.