Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

pixelcanvas/v0 package

Overview

Package pixelcanvas is a shared 16x16 pixel canvas: anyone can paint one cell at a time from a fixed 9-colour palette, and the canvas renders in gnoweb as a grid of coloured blocks.

The canvas is a flat [Size*Size]int of palette indices held in realm state — a fixed-size array rather than a tree, because every cell exists from the start and the grid is walked in full on every render. Painting is last-write-wins; the realm keeps who painted each cell and a per-address tally, so the board doubles as a contribution leaderboard.

A stateful app with nothing reusable to extract, so it ships as a lone realm rather than a p/ library + demo pair.

Functions

At

func At(x, y int) string

At returns the palette name of the cell at (x, y), or "" when out of bounds.

Params

Command

gnokey query vm/qeval -remote "http://127.0.0.1:26657" -data "gno.land/r/moul/x/daily/pixelcanvas/v0.At(,)"

Result

Paint

func Paint(cur realm, x, y int, colour string) int

Paint colours the cell at (x, y) and returns the total number of strokes.

Coordinates are 0-based with (0,0) at the top-left. Colour is a palette name ("red", "blue", …) — see Palette. Painting over an existing cell is allowed: the canvas is last-write-wins, which is the whole point of a shared board.

Params

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/pixelcanvas/v0" -func "Paint" -args $'' -args $'' -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "http://127.0.0.1:26657" ADDRESSgnokey query -remote "http://127.0.0.1:26657" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/pixelcanvas/v0" -func "Paint" -args $'' -args $'' -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "http://127.0.0.1:26657" call.tx
  

PainterAt

func PainterAt(x, y int) string

PainterAt returns the address that last painted (x, y), or "" if untouched.

Params

Command

gnokey query vm/qeval -remote "http://127.0.0.1:26657" -data "gno.land/r/moul/x/daily/pixelcanvas/v0.PainterAt(,)"

Result

Palette

func Palette() string

Palette returns the accepted colour names, comma-separated.

Command

gnokey query vm/qeval -remote "http://127.0.0.1:26657" -data "gno.land/r/moul/x/daily/pixelcanvas/v0.Palette()"

Result

Render

func Render(path string) string

Render renders the canvas for gnoweb.

Example
1Render("")        / Render("/") -> the canvas, palette and leaderboard
2Render("/<x>,<y>")              -> who painted that cell, and what colour

Param

Command

gnokey query vm/qeval -remote "http://127.0.0.1:26657" -data "gno.land/r/moul/x/daily/pixelcanvas/v0.Render()"

Result

Strokes

func Strokes() int

Strokes returns how many paints the canvas has taken.

Command

gnokey query vm/qeval -remote "http://127.0.0.1:26657" -data "gno.land/r/moul/x/daily/pixelcanvas/v0.Strokes()"

Result