Rhai scripting

Pixel Stroke embeds Rhai — a Rust-native scripting language that compiles to a tight interpreter and runs in the editor's WASM bundle. Every ps_* function listed in the API reference is registered on the Rhai engine and is callable from your scripts.

Scripts live as .rhai files on disk (the desktop app reads them live), or pasted directly into the in-editor console. The same script runs on both — there's no separate web/native split for the script surface.

Hello, halftone stable

Your first script. Defines a macro that applies three filters in sequence, then runs it on the active layer.

// Save as scripts/macros/halftone.rhai

fn halftone() {
  ps_filter_posterize(4);
  ps_filter_pixelate(3);
  ps_filter_edge_detect(0.4);
}

halftone();

Run it from the in-editor console:

script source("scripts/macros/halftone.rhai")

Macros stable

Any Rhai fn you define becomes a callable macro. Macros are first-class — they're not strings or magic; they're functions that close over the script's scope and can call any registered binding.

The shipped editor uses macros for repeatable workflows. Examples ship under scripts/macros/ in the pixel-stroke repo.

Panel scripts stable

The editor's side-panels (toolbar, layer list, timeline, color picker, palette manager, tilemap, atlas, bones, navigator, artboard) are all Rhai scripts under scripts/panels/. The same Rhai engine drives them.

This means you can fork a panel, modify its behavior, or write a new one entirely — without touching the Rust core.

Layer + animation flow stable

Working with layers + frames programmatically:

// add a highlights layer and blink it
ps.layer_add("Highlights");
ps.layer_opacity(80);

// duplicate the current frame; subsequent edits affect the new frame
ps.animation_duplicate_frame();

// pixel-perfect mode for crisp 1px strokes
ps_brush_pixel_perfect(true);

Building a custom palette stable

// build a 4-stop custom palette
ps_palette_new("Aurora");
ps_palette_add_color("Aurora", "#0a0a1e");
ps_palette_add_color("Aurora", "#3a8fff");
ps_palette_add_color("Aurora", "#ec2a2a");
ps_palette_set_active("Aurora");

Same approach works for loading GIMP .gpl or simple hex lists — see the API reference for the full palette family.

Coming next soon

  • Keybinding registration — keybind.set("B", "halftone")
  • Command palette entries — cmd.register(name, fn, hint)
  • Stamp-brush capture from a selection (the editor exposes the binding once the underlying tool lands).