v0 source pure
Package canvas is a fixed-size, 16-color pixel grid.
View source
canvas
Pure package gno.land/p/g19t6f4f4ptt3m949jznalfsx2h8aj696llul0nj/canvas/v0: a fixed-size grid of palette
indexes with lazy per-row allocation, plus the x,y,color;... batch codec.
Used by the realm gno.land/r/g19t6f4f4ptt3m949jznalfsx2h8aj696llul0nj/million/v0, which adds pricing and
access control. The package itself holds no chain state and has no chain
imports, so it is fully covered by plain unit tests (gno test .).
New(width, height): empty canvas, sides between 1 and 10000.Set(Pixel),Get(x, y),Check(Pixel): paint, read, validate.Rows(from, to): rows as one hex digit per pixel, no separators.ParsePixels,Encode,ParseColor: the batch format.Palette: 16 CSS colors, index 0 being "never painted".
Package canvas is a fixed-size, 16-color pixel grid.
It holds no chain state and knows nothing about payments: the realm gno.land/r/g19t6f4f4ptt3m949jznalfsx2h8aj696llul0nj/million/v0 wraps it with pricing and access control.
Storage layout: one []byte per row, allocated on first paint. A row that was never painted is nil and costs nothing. Each byte holds a palette index; Blank (0) means "never painted".
1
2
var ErrOutOfRange, ErrInvalidColor, ErrBadPixel
var Palette
Palette maps a color index to its CSS hex value. Index 0 is Blank and is rendered as white by clients.
4
func Encode
Encode is the inverse of ParsePixels.
func ParseColor
ParseColor converts a decimal color index, rejecting Blank.
func New
New returns an empty canvas. It panics on a non-positive or oversized side.
func ParsePixels
ParsePixels decodes "x,y,color;x,y,color;...". A trailing ';' is allowed. It validates the syntax and the color range but not the coordinates, which depend on the canvas: call Check for that.
2
type Canvas
structCanvas is a width x height grid of palette indexes.
Methods on Canvas
func Check
method on CanvasCheck reports whether p can be painted on this canvas.
func Get
method on CanvasGet returns the color at (x, y). Out-of-range coordinates panic.
func Height
method on Canvasfunc Painted
method on CanvasPainted is the number of pixels that are not Blank.
func Rows
method on CanvasRows encodes rows [from, to) as one hex digit per pixel, row after row, with no separator. Clients slice it with the known width.
func Set
method on CanvasSet paints p. It panics when Check(p) fails.
func Width
method on Canvastype Pixel
structPixel is one paint request.
3
- errors stdlib
- strconv stdlib
- strings stdlib