Skip to main content

Module output

Module output 

Source
Expand description

Image and animation encoding; callers own destinations and publication.

Every export is STATIC_EXPORT_SCALE times the native canvas on each side, so the pixel art stays crisp: encode_png for the still, encode_svg for a vector document of the same pixels, encode_gif for a behavior’s loop, and encode_preview_html for a page that shows the GIF and PNG beside it on GitHub’s light and dark page colors.

Enums§

GifEncodingError
Why a GIF was not produced.

Constants§

STATIC_EXPORT_SCALE
Each native pixel becomes this many export pixels on each side.
STATIC_HEIGHT_PIXELS
Height of every exported image.
STATIC_WIDTH_PIXELS
Width of every exported image.

Functions§

encode_gif
Encode a seamless loop as an animated GIF at the static export size, repeating each native pixel in both dimensions. The GIF repeats forever at FRAMES_PER_SECOND; each delay, in hundredths of a second, is the step in a rounded running total, so a loop lasts exactly its frame count divided by the frame rate. Each frame stores only the box around its drawn pixels, with an exact palette of its colors, and that box clears before the next frame. Colors are never approximated: a frame with more than 255 colors or a partly transparent pixel fails instead. Identical frames produce identical bytes without I/O, timestamps, or input mutation.
encode_png
Encode a static PNG by repeating each native pixel in both dimensions. Preserve its color and alpha without interpolation, timestamps, I/O, or mutation. Encoding errors propagate before the caller publishes any resulting bytes.
encode_preview_html
Build a page that previews koi.gif and koi.png, read from beside it, on GitHub’s light and dark page colors under the given caption. It draws nothing itself and loads no scripts or outside files, so it shows exactly what was generated.
encode_svg
Encode a self-contained SVG at the static export size with native pixel coordinates. Equal neighboring pixels share a rectangle within their row. Transparent pixels are omitted; visible pixels retain their color and alpha. Identical frames produce identical documents without I/O, timestamps, external assets, or input mutation.