moui_p5

    p5-style creative coding for MoUI: sketch lifecycle, color, math, paths, images, and surfaces drawn through MoUI command streams

    moui
    p5
    creative
    addon
    Download zip
    Author
    Version
    0.7.3
    License
    Apache-2.0
    Last updated
    58 minutes ago
    Downloads
    9

    #moui_p5

    p5-style creative coding for MoUI. The addon owns the renderer-neutral p5 core (sketch lifecycle, color, math, paths, images, surfaces) and a MoUI adapter that replays a sketch as DrawCommand streams, so the same sketch runs on every MoUI renderer.

    #Packages

    • wzzc-dev/moui_p5 — core sketch/color/math/path/image/surface API and a Recorder surface for headless tests.
    • wzzc-dev/moui_p5/moui — SketchView canvas view, input mapping, canvas readback, and draw-command adapter.
    • wzzc-dev/moui_p5/http — native async https: image loader (RemoteImageLoader) for load_image_async.

    #Host byte I/O

    The addon carries no filesystem dependency. Image loading and saving go through FilePorts, a loader/saver closure pair injected by the host:

    • install once with set_default_file_ports, and sketches created afterwards inherit it; or
    • pass file_ports= to Sketch::new, or call Sketch::set_file_ports.

    FilePorts::none() rejects every operation, which keeps wasm hosts on the previous "cannot read or write files" behavior. Native hosts typically back the ports with the platform filesystem package; tests use an in-memory byte map.

    #Example

    The runnable demo lives in examples/p5_sketch: a native macOS Skia entrypoint, a wasm entrypoint, and the interactive demos in examples/p5_sketch/app.

    ImageFetcher

    type ImageFetcher = (String, (Bytes?) -> Unit) -> Unit

    Host-provided byte fetcher for load_image_async. The host receives the source and a completion callback; it may complete later on its event loop. The p5 core decodes PNG bytes and fills the placeholder image in place.

    ColorArg

    pub(open) trait ColorArg {
    fn to_color(Self, ColorMode, ColorRanges) -> Color
    }

    Values accepted by fill, stroke, background, and color.
    impl ColorArg for Int
    impl ColorArg for Double
    impl ColorArg for String
    impl ColorArg for Tuple2[A, B]
    impl ColorArg for Tuple3[A, B, C]
    impl ColorArg for Tuple4[A, B, C, D]

    ImageSource

    pub(open) trait ImageSource {
    fn image_size(Self) -> (Double, Double)
    fn draw_as_image(Self, Sketch, Double, Double, Double, Double) -> Unit
    }

    Something Sketch::image can draw: a pixel Image or a graphics sketch.

    Num

    pub(open) trait Num {
    fn to_num(Self) -> Double
    }

    Numbers accepted inside color tuples. Int and Double can be mixed.
    impl Num for Int
    impl Num for Double

    Surface

    pub(open) trait Surface {
    fn set_transform(Self, Matrix) -> Unit
    fn save(Self) -> Unit
    fn restore(Self) -> Unit
    fn fill_path(Self, Path, Color) -> Unit
    fn stroke_path(Self, Path, Color, Double, StrokeCap, StrokeJoin) -> Unit
    fn fill_rect(Self, Double, Double, Double, Double, Color) -> Unit
    fn fill_rounded_rect(Self, Double, Double, Double, Double, Double, Color) -> Unit
    fn stroke_rounded_rect(Self, Double, Double, Double, Double, Double, Color, Double) -> Unit
    fn clear_rect(Self, Double, Double, Double, Double) -> Unit
    fn draw_image(Self, Image, Double, Double, Double, Double, Double, Color?) -> Unit
    fn clip_path(Self, Path) -> Unit
    fn clip_end(Self) -> Unit
    fn fill_text(Self, String, Double, Double, Color, Color?, Double, FontSpec, HAlign, VAlign) -> Unit
    fn measure_width(Self, String, FontSpec) -> Double
    fn text_metrics(Self, FontSpec) -> TextMetrics
    fn set_blend_mode(Self, BlendMode) -> Unit
    fn set_smoothing(Self, Bool) -> Unit
    }

    AngleMode

    pub(all) enum AngleMode {
    Radians
    Degrees
    } derive(Eq)

    AngleMode::equal

    fn AngleMode::equal(AngleMode, AngleMode) -> Bool
    automatically derived

    AngleMode::not_equal

    fn AngleMode::not_equal(x : AngleMode, y : AngleMode) -> Bool
    automatically derived

    ArcMode

    pub(all) enum ArcMode {
    Open
    Chord
    Pie
    } derive(Eq)

    How arc connects its endpoints.

    ArcMode::equal

    fn ArcMode::equal(ArcMode, ArcMode) -> Bool
    automatically derived

    ArcMode::not_equal

    fn ArcMode::not_equal(x : ArcMode, y : ArcMode) -> Bool
    automatically derived

    BlendMode

    pub(all) enum BlendMode {
    Blend
    Multiply
    Screen
    Overlay
    Darken
    Lighten
    Add
    Difference
    Exclusion
    HardLight
    SoftLight
    Dodge
    Burn
    } derive(Eq)

    Blend modes the core understands. Backends map them best-effort.

    BlendMode::equal

    fn BlendMode::equal(BlendMode, BlendMode) -> Bool
    automatically derived

    BlendMode::not_equal

    fn BlendMode::not_equal(x : BlendMode, y : BlendMode) -> Bool
    automatically derived

    Color

    pub(all) struct Color {
    r : Double
    g : Double
    b : Double
    a : Double
    } derive(Eq,
    Debug
    )

    impl ColorArg for Color

    Color::alpha

    fn Color::alpha(self : Color) -> Double

    Color::black

    fn Color::black() -> Color

    Color::blue

    fn Color::blue(self : Color) -> Double

    Color::brightness

    fn Color::brightness(self : Color) -> Double

    HSB brightness in [0, 100].

    Color::equal

    fn Color::equal(Color, Color) -> Bool
    automatically derived

    Color::from_argb

    fn Color::from_argb(value : UInt) -> Color

    Builds a color from a packed 0xAARRGGBB value.

    Color::green

    fn Color::green(self : Color) -> Double

    Color::hue

    fn Color::hue(self : Color) -> Double

    Hue in [0, 360).

    Color::lerp

    fn Color::lerp(self : Color, other : Color, amount : Double) -> Color

    Color::lightness

    fn Color::lightness(self : Color) -> Double

    HSL lightness in [0, 100].

    Color::new

    fn Color::new(r : Double, g : Double, b : Double, a : Double) -> Color

    Color::not_equal

    fn Color::not_equal(x : Color, y : Color) -> Bool
    automatically derived

    Color::red

    fn Color::red(self : Color) -> Double

    Color::rgb

    fn Color::rgb(r : Double, g : Double, b : Double, a? : Double) -> Color

    Builds a color from 0..255 components.

    Color::saturation

    fn Color::saturation(self : Color) -> Double

    HSB saturation in [0, 100].

    Color::solid

    fn Color::solid(r : Double, g : Double, b : Double) -> Color

    Color::to_color

    fn Color::to_color(self : Color, _ : ColorMode, _ : ColorRanges) -> Color

    Color::to_repr

    automatically derived

    Color::to_tuple

    fn Color::to_tuple(self : Color) -> (Double, Double, Double, Double)

    Color::transparent

    fn Color::transparent() -> Color

    Color::white

    fn Color::white() -> Color

    Color::with_alpha

    fn Color::with_alpha(self : Color, alpha : Double) -> Color

    ColorMode

    pub(all) enum ColorMode {
    RGB
    HSB
    HSL
    } derive(Eq)

    Color spaces supported on input.

    ColorMode::equal

    fn ColorMode::equal(ColorMode, ColorMode) -> Bool
    automatically derived

    ColorMode::not_equal

    fn ColorMode::not_equal(x : ColorMode, y : ColorMode) -> Bool
    automatically derived

    ColorRanges

    pub(all) struct ColorRanges {
    c0 : Double
    c1 : Double
    c2 : Double
    alpha : Double
    } derive(Eq)

    Upper bounds used to map user numbers into the normalized color model.

    ColorRanges::equal

    fn ColorRanges::equal(ColorRanges, ColorRanges) -> Bool
    automatically derived

    ColorRanges::new

    fn ColorRanges::new(c0 : Double, c1 : Double, c2 : Double, alpha : Double) -> ColorRanges

    ColorRanges::not_equal

    fn ColorRanges::not_equal(x : ColorRanges, y : ColorRanges) -> Bool
    automatically derived

    ColorRanges::uniform

    fn ColorRanges::uniform(mode : ColorMode, maximum : Double) -> ColorRanges

    FilePorts

    pub struct FilePorts {
    load : (String) -> Bytes?
    save : (String, Bytes) -> Bool
    }

    Host byte I/O used by Sketch image loading and saving.

    The p5 addon keeps no filesystem dependency of its own: the host installs FilePorts backed by host file APIs (native filesystem reads on native, browser storage on Web, an in-memory map in tests, ...). Ports that reject every operation (FilePorts::none) keep wasm hosts on the previous "cannot read or write files" behavior instead of failing to build.

    FilePorts::load

    fn FilePorts::load(self : FilePorts, path : String) -> Bytes?

    Reads path through the installed loader, or None when it rejects.

    FilePorts::new

    fn FilePorts::new(load~ : (String) -> Bytes?, save~ : (String, Bytes) -> Bool) -> FilePorts

    Builds ports from a loader and a saver.

    load returns None when the path cannot be read; save returns false when the path cannot be written. Implementations report failures through those return values instead of raising, so sketch code never needs to catch host errors.

    FilePorts::none

    fn FilePorts::none() -> FilePorts

    Ports that reject every operation, for hosts without file I/O.

    FilePorts::save

    fn FilePorts::save(self : FilePorts, path : String, bytes : Bytes) -> Bool

    Writes bytes to path through the installed saver.

    Filter

    pub(all) enum Filter {
    Threshold(Double)
    Gray
    Opaque
    Invert
    Posterize(Int)
    Blur(Double)
    Erode
    Dilate
    } derive(Eq)

    CPU image filters, mirroring p5's filter() constants.

    Filter::equal

    fn Filter::equal(Filter, Filter) -> Bool
    automatically derived

    Filter::not_equal

    fn Filter::not_equal(x : Filter, y : Filter) -> Bool
    automatically derived

    FontSpec

    pub(all) struct FontSpec {
    family : String
    size : Double
    weight : Int
    italic : Bool
    leading : Double
    } derive(Eq)

    FontSpec::equal

    fn FontSpec::equal(FontSpec, FontSpec) -> Bool
    automatically derived

    FontSpec::new

    fn FontSpec::new(family? : String, size? : Double, weight? : Int, italic? : Bool, leading? : Double) -> FontSpec

    FontSpec::not_equal

    fn FontSpec::not_equal(x : FontSpec, y : FontSpec) -> Bool
    automatically derived

    HAlign

    pub(all) enum HAlign {
    Left
    HCenter
    Right
    } derive(Eq)

    HAlign::equal

    fn HAlign::equal(HAlign, HAlign) -> Bool
    automatically derived

    HAlign::not_equal

    fn HAlign::not_equal(x : HAlign, y : HAlign) -> Bool
    automatically derived

    Image

    pub struct Image {
    pixels : FixedArray[Byte]
    // private fields
    }

    A writable RGBA8 image / graphics buffer.

    pixels is straight (non-premultiplied) RGBA in row-major order. Drawing the image goes through Surface::draw_image; the MoUI adapter encodes the buffer as a PNG data URI and emits DrawCommand::DrawImage, so the same image works with Skia, Sun, and the browser image loader.

    Image::copy

    fn Image::copy(self : Image) -> Image

    Image::draw_as_image

    fn Image::draw_as_image(self : Image, target : Sketch, x : Double, y : Double, width : Double, height : Double) -> Unit

    Image::fill

    fn Image::fill(self : Image, color : Color) -> Unit

    Image::filter

    fn Image::filter(self : Image, filter : Filter) -> Unit

    Applies a CPU filter in place, like p5's filter() on a graphics buffer.

    Image::from_png_bytes

    fn Image::from_png_bytes(bytes : Bytes) -> Image?

    Decodes an 8-bit non-interlaced RGB/RGBA PNG into an Image.

    Image::from_rgba

    fn Image::from_rgba(width : Int, height : Int, pixels : FixedArray[Byte]) -> Image?

    Builds an image from tightly packed straight RGBA8 pixels. The input is copied, so later mutation of pixels does not affect the image.

    Image::from_rgba_bytes

    fn Image::from_rgba_bytes(width : Int, height : Int, row_bytes : Int, pixels : Bytes) -> Image?

    Builds an image from straight RGBA8 rows with a host-supplied stride. This is the entry point for renderer readback, whose rows may carry padding.

    Image::get

    fn Image::get(self : Image, x : Int, y : Int) -> Color

    Returns the pixel at (x, y), or transparent outside the image.

    Image::height

    fn Image::height(self : Image) -> Int

    Image::image_size

    fn Image::image_size(self : Image) -> (Double, Double)

    Image::load_pixels

    fn Image::load_pixels(self : Image) -> Unit

    Pixels are already resident; kept for p5 API compatibility.

    Image::new

    fn Image::new(width : Int, height : Int, fill? : Color) -> Image

    Image::resize

    fn Image::resize(self : Image, width : Int, height : Int) -> Unit

    Image::save

    fn Image::save(self : Image, path : String, saver~ : (String, Bytes) -> Bool) -> Bool

    Encodes the image as a PNG and hands the bytes to saver, which returns false when it cannot write the path. The addon carries no filesystem dependency: Sketch::save_image routes through the sketch's FilePorts, and direct callers pass a host-backed saver (for example the native filesystem package in the demo, an in-memory map in tests).

    Image::set

    fn Image::set(self : Image, x : Int, y : Int, color : Color) -> Unit

    Writes one pixel; out-of-bounds writes are ignored.

    Image::tinted

    fn Image::tinted(self : Image, tint : Color) -> Image

    Returns a tinted copy (RGB multiplied by tint; alpha multiplied too).

    Image::to_png_bytes

    fn Image::to_png_bytes(self : Image) -> Bytes

    PNG encoding for Image: 8-bit straight RGBA, non-interlaced, filter 0 rows. The framework's neutral @core.RgbaBuffer owns the byte-level codec; the addon keeps its own Image / to_png_bytes naming on top so sketch code does not depend on a codec package directly and there is no second framework pixel type.

    Image::update_pixels

    fn Image::update_pixels(self : Image) -> Unit

    Pixels writes are immediate; kept for p5 API compatibility.

    Image::width

    fn Image::width(self : Image) -> Int

    Matrix

    pub(all) struct Matrix {
    a : Double
    b : Double
    c : Double
    d : Double
    tx : Double
    ty : Double
    } derive(Eq)

    A 2D affine transform in the same layout MoUI's Transform2D uses: x' = a*x + c*y + tx, y' = b*x + d*y + ty.

    Matrix::compose

    fn Matrix::compose(self : Matrix, other : Matrix) -> Matrix

    self * other: apply other first, then self.

    Matrix::equal

    fn Matrix::equal(Matrix, Matrix) -> Bool
    automatically derived

    Matrix::identity

    fn Matrix::identity() -> Matrix

    Matrix::inverse

    fn Matrix::inverse(self : Matrix) -> Matrix

    Matrix::is_identity

    fn Matrix::is_identity(self : Matrix) -> Bool

    Matrix::not_equal

    fn Matrix::not_equal(x : Matrix, y : Matrix) -> Bool
    automatically derived

    Matrix::rotation

    fn Matrix::rotation(angle : Double) -> Matrix

    Matrix::scale_factor

    fn Matrix::scale_factor(self : Matrix) -> Double

    Average scale factor, used for stroke widths and text sizes.

    Matrix::scaling

    fn Matrix::scaling(x : Double, y : Double) -> Matrix

    Matrix::shear

    fn Matrix::shear(x : Double, y : Double) -> Matrix

    Matrix::transform_point

    fn Matrix::transform_point(self : Matrix, x : Double, y : Double) -> (Double, Double)

    Matrix::translation

    fn Matrix::translation(x : Double, y : Double) -> Matrix

    Noise

    pub struct Noise {
    // private fields
    }

    A Perlin noise generator matching p5.js's noise, noiseSeed, and noiseDetail.

    Noise::detail

    fn Noise::detail(self : Noise, octaves : Int, falloff? : Double) -> Unit

    Noise::new

    fn Noise::new(seed : Double) -> Noise

    Noise::noise

    fn Noise::noise(self : Noise, x : Double, y? : Double, z? : Double) -> Double

    Noise::set_seed

    fn Noise::set_seed(self : Noise, seed : Double) -> Unit

    NullSurface

    pub(all) struct NullSurface {
    marker : Bool
    }

    A do-nothing surface used while a sketch is not bound to a frame.

    NullSurface::clear_rect

    fn NullSurface::clear_rect(_ : NullSurface, _ : Double, _ : Double, _ : Double, _ : Double) -> Unit

    NullSurface::clip_end

    fn NullSurface::clip_end(_ : NullSurface) -> Unit

    NullSurface::clip_path

    fn NullSurface::clip_path(_ : NullSurface, _ : Path) -> Unit

    NullSurface::draw_image

    fn NullSurface::draw_image(_ : NullSurface, _ : Image, _ : Double, _ : Double, _ : Double, _ : Double, _ : Double, _ : Color?) -> Unit

    NullSurface::fill_path

    fn NullSurface::fill_path(_ : NullSurface, _ : Path, _ : Color) -> Unit

    NullSurface::fill_rect

    fn NullSurface::fill_rect(_ : NullSurface, _ : Double, _ : Double, _ : Double, _ : Double, _ : Color) -> Unit

    NullSurface::fill_rounded_rect

    fn NullSurface::fill_rounded_rect(_ : NullSurface, _ : Double, _ : Double, _ : Double, _ : Double, _ : Double, _ : Color) -> Unit

    NullSurface::fill_text

    fn NullSurface::fill_text(_ : NullSurface, _ : String, _ : Double, _ : Double, _ : Color, _ : Color?, _ : Double, _ : FontSpec, _ : HAlign, _ : VAlign) -> Unit

    NullSurface::is_null

    fn NullSurface::is_null(self : NullSurface) -> Bool

    NullSurface::measure_width

    fn NullSurface::measure_width(_ : NullSurface, text : String, font : FontSpec) -> Double

    NullSurface::new

    NullSurface::restore

    fn NullSurface::restore(_ : NullSurface) -> Unit

    NullSurface::save

    fn NullSurface::save(_ : NullSurface) -> Unit

    NullSurface::set_blend_mode

    fn NullSurface::set_blend_mode(_ : NullSurface, _ : BlendMode) -> Unit

    NullSurface::set_smoothing

    fn NullSurface::set_smoothing(_ : NullSurface, _ : Bool) -> Unit

    NullSurface::set_transform

    fn NullSurface::set_transform(_ : NullSurface, _ : Matrix) -> Unit

    NullSurface::stroke_path

    fn NullSurface::stroke_path(_ : NullSurface, _ : Path, _ : Color, _ : Double, _ : StrokeCap, _ : StrokeJoin) -> Unit

    NullSurface::stroke_rounded_rect

    fn NullSurface::stroke_rounded_rect(_ : NullSurface, _ : Double, _ : Double, _ : Double, _ : Double, _ : Double, _ : Color, _ : Double) -> Unit

    NullSurface::text_metrics

    fn NullSurface::text_metrics(_ : NullSurface, font : FontSpec) -> TextMetrics

    Path

    pub(all) struct Path {
    commands : Array[PathCmd]
    }

    Path::arc_at

    fn Path::arc_at(self : Path, cx : Double, cy : Double, rx : Double, ry : Double, start_angle : Double, stop_angle : Double, mode : ArcMode) -> Unit

    Appends an elliptical arc. Angles are radians and increase clockwise on screen (the canvas convention: positive y points down).

    Path::bezier_at

    fn Path::bezier_at(self : Path, x1 : Double, y1 : Double, x2 : Double, y2 : Double, x3 : Double, y3 : Double, x4 : Double, y4 : Double) -> Unit

    Appends a quadratic/cubic Bézier through one segment.

    Path::bounds

    fn Path::bounds(self : Path) -> (Double, Double, Double, Double)

    A conservative bounding box used for rectangular clip approximation.

    Path::close

    fn Path::close(self : Path) -> Unit

    Path::commands

    fn Path::commands(self : Path) -> Array[PathCmd]

    Path::copy

    fn Path::copy(self : Path) -> Path

    Path::cubic_to

    fn Path::cubic_to(self : Path, c1x : Double, c1y : Double, c2x : Double, c2y : Double, x : Double, y : Double) -> Unit

    Path::ellipse_at

    fn Path::ellipse_at(self : Path, cx : Double, cy : Double, rx : Double, ry : Double) -> Unit

    Appends an axis-aligned ellipse as four cubic segments.

    Path::is_empty_path

    fn Path::is_empty_path(self : Path) -> Bool

    Path::line_to

    fn Path::line_to(self : Path, x : Double, y : Double) -> Unit

    Path::move_to

    fn Path::move_to(self : Path, x : Double, y : Double) -> Unit

    Path::new

    fn Path::new() -> Path

    Path::polygon

    fn Path::polygon(self : Path, points : ArrayView[(Double, Double)]) -> Unit

    Path::quad_to

    fn Path::quad_to(self : Path, cx : Double, cy : Double, x : Double, y : Double) -> Unit

    Path::rect_at

    fn Path::rect_at(self : Path, x : Double, y : Double, width : Double, height : Double) -> Unit

    Appends a rectangle in corner coordinates.

    Path::rounded_rect_at

    fn Path::rounded_rect_at(self : Path, x : Double, y : Double, width : Double, height : Double, tl : Double, tr : Double, br : Double, bl : Double) -> Unit

    Appends a rectangle with independent corner radii.

    PathCmd

    pub(all) enum PathCmd {
    MoveTo(Double, Double)
    LineTo(Double, Double)
    QuadTo(Double, Double, Double, Double)
    CubicTo(Double, Double, Double, Double, Double, Double)
    Close
    } derive(Eq)

    PathCmd::equal

    fn PathCmd::equal(PathCmd, PathCmd) -> Bool
    automatically derived

    PathCmd::not_equal

    fn PathCmd::not_equal(x : PathCmd, y : PathCmd) -> Bool
    automatically derived

    Random

    pub struct Random {
    // private fields
    }

    A seedable pseudo-random generator matching p5.js's randomSeed / random sequence (Numerical Recipes LCG).

    Random::choice

    fn[T] Random::choice(self : Random, choices : ArrayView[T]) -> T

    Random::gaussian

    fn Random::gaussian(self : Random, mean? : Double, sd? : Double) -> Double

    Marsaglia polar method, as in p5.js randomGaussian.

    Random::new

    fn Random::new(seed : Double) -> Random

    Random::next

    fn Random::next(self : Random) -> Double

    Random::range

    fn Random::range(self : Random, min : Double, max : Double) -> Double

    Random::set_seed

    fn Random::set_seed(self : Random, seed : Double) -> Unit

    Recorder

    pub struct Recorder {
    log : Array[String]
    }

    A surface that records every drawing call as one text line. Text is measured as half the font size per character, so sketches can run headless in native tests with deterministic output.
    impl Surface for Recorder

    Recorder::clear_rect

    fn Recorder::clear_rect(self : Recorder, x : Double, y : Double, width : Double, height : Double) -> Unit

    Recorder::clip_end

    fn Recorder::clip_end(self : Recorder) -> Unit

    Recorder::clip_path

    fn Recorder::clip_path(self : Recorder, path : Path) -> Unit

    Recorder::draw_image

    fn Recorder::draw_image(self : Recorder, image : Image, x : Double, y : Double, width : Double, height : Double, opacity : Double, tint : Color?) -> Unit

    Recorder::fill_path

    fn Recorder::fill_path(self : Recorder, path : Path, color : Color) -> Unit

    Recorder::fill_rect

    fn Recorder::fill_rect(self : Recorder, x : Double, y : Double, width : Double, height : Double, color : Color) -> Unit

    Recorder::fill_rounded_rect

    fn Recorder::fill_rounded_rect(self : Recorder, x : Double, y : Double, width : Double, height : Double, radius : Double, color : Color) -> Unit

    Recorder::fill_text

    fn Recorder::fill_text(self : Recorder, text : String, x : Double, y : Double, color : Color, stroke : Color?, stroke_width : Double, font : FontSpec, align_h : HAlign, align_v : VAlign) -> Unit

    Recorder::measure_width

    fn Recorder::measure_width(_ : Recorder, text : String, font : FontSpec) -> Double

    Recorder::new

    fn Recorder::new() -> Recorder

    Recorder::restore

    fn Recorder::restore(self : Recorder) -> Unit

    Recorder::save

    fn Recorder::save(self : Recorder) -> Unit

    Recorder::set_blend_mode

    fn Recorder::set_blend_mode(self : Recorder, mode : BlendMode) -> Unit

    Recorder::set_smoothing

    fn Recorder::set_smoothing(self : Recorder, enabled : Bool) -> Unit

    Recorder::set_transform

    fn Recorder::set_transform(self : Recorder, matrix : Matrix) -> Unit

    Recorder::snapshot

    fn Recorder::snapshot(self : Recorder) -> Array[String]

    Peeks at the recorded calls without clearing.

    Recorder::stroke_path

    fn Recorder::stroke_path(self : Recorder, path : Path, color : Color, width : Double, _cap : StrokeCap, _join : StrokeJoin) -> Unit

    Recorder::stroke_rounded_rect

    fn Recorder::stroke_rounded_rect(self : Recorder, x : Double, y : Double, width : Double, height : Double, radius : Double, color : Color, stroke_width : Double) -> Unit

    Recorder::take

    fn Recorder::take(self : Recorder) -> Array[String]

    Returns the recorded calls and clears the log.

    Recorder::text_metrics

    fn Recorder::text_metrics(_ : Recorder, font : FontSpec) -> TextMetrics

    ShapeMode

    pub(all) enum ShapeMode {
    Corner
    Corners
    Center
    Radius
    } derive(Eq)

    The anchor mode used by rect and ellipse.

    ShapeMode::equal

    fn ShapeMode::equal(ShapeMode, ShapeMode) -> Bool
    automatically derived

    ShapeMode::not_equal

    fn ShapeMode::not_equal(x : ShapeMode, y : ShapeMode) -> Bool
    automatically derived

    Sketch

    pub struct Sketch {
    width : Double
    height : Double
    frame_count : Int
    delta_time : Double
    elapsed_ms : Double
    mouse_x : Double
    mouse_y : Double
    pmouse_x : Double
    pmouse_y : Double
    moved_x : Double
    moved_y : Double
    mouse_is_pressed : Bool
    mouse_button : Int
    touches : Array[Touch]
    composing : Bool
    composition_text : String
    last_input_text : String
    key : String
    code : String
    key_is_pressed : Bool
    key_code : Int
    focused : Bool
    // private fields
    }

    A p5 sketch.

    Sketch::acos

    fn Sketch::acos(self : Sketch, value : Double) -> Double

    Sketch::alpha

    fn[C : ColorArg] Sketch::alpha(self : Sketch, color : C) -> Double

    Sketch::angle_mode

    fn Sketch::angle_mode(self : Sketch, mode : AngleMode) -> Unit

    Sketch::apply_matrix

    fn Sketch::apply_matrix(self : Sketch, a : Double, b : Double, c : Double, d : Double, e : Double, f : Double) -> Unit

    Sketch::arc

    fn Sketch::arc(self : Sketch, x : Double, y : Double, width : Double, height : Double, start : Double, stop : Double, mode? : ArcMode) -> Unit

    Sketch::asin

    fn Sketch::asin(self : Sketch, value : Double) -> Double

    Sketch::atan

    fn Sketch::atan(self : Sketch, value : Double) -> Double

    Sketch::atan2

    fn Sketch::atan2(self : Sketch, y : Double, x : Double) -> Double

    Sketch::background

    fn[C : ColorArg] Sketch::background(self : Sketch, color : C) -> Unit

    Sketch::begin_contour

    fn Sketch::begin_contour(self : Sketch) -> Unit

    Starts a new subpath inside the current shape. The next vertex starts with a MoveTo, so independent contours can be filled with one end_shape.

    Sketch::begin_shape

    fn Sketch::begin_shape(self : Sketch) -> Unit

    Sketch::bezier

    fn Sketch::bezier(self : Sketch, x1 : Double, y1 : Double, x2 : Double, y2 : Double, x3 : Double, y3 : Double, x4 : Double, y4 : Double) -> Unit

    Sketch::bezier_vertex

    fn Sketch::bezier_vertex(self : Sketch, c1x : Double, c1y : Double, c2x : Double, c2y : Double, x : Double, y : Double) -> Unit

    Adds one cubic Bézier segment to the current shape.

    Sketch::blend_mode

    fn Sketch::blend_mode(self : Sketch, mode : BlendMode) -> Unit

    Sketch::blue

    fn[C : ColorArg] Sketch::blue(self : Sketch, color : C) -> Double

    Sketch::brightness

    fn[C : ColorArg] Sketch::brightness(self : Sketch, color : C) -> Double

    Sketch::canvas_epoch

    fn Sketch::canvas_epoch(self : Sketch) -> Int

    Monotonic counter bumped when the canvas is fully replaced (background with opaque alpha, clear, or reset). Retained surfaces use it to drop stale display-list history.

    Sketch::circle

    fn Sketch::circle(self : Sketch, x : Double, y : Double, diameter : Double) -> Unit

    Sketch::clear

    fn Sketch::clear(self : Sketch) -> Unit

    Sketch::clear_image_fetcher

    fn Sketch::clear_image_fetcher(self : Sketch) -> Unit

    Removes the host byte fetcher; later load_image_async calls fall back to the synchronous paths only.

    Sketch::clip

    fn Sketch::clip(self : Sketch, path : Path, body : (Sketch) -> Unit) -> Unit

    Scoped clip helper: uses path as the clip region for body.

    Sketch::clip_path_begin

    fn Sketch::clip_path_begin(self : Sketch, path : Path) -> Unit

    Applies a rectangular clip to everything drawn until clip_path_end.

    The draw-command protocol exposes rectangular clipping; a non-rectangular clip path is conservatively clipped to its bounding box.

    Sketch::clip_path_end

    fn Sketch::clip_path_end(self : Sketch) -> Unit

    Sketch::color

    fn[C : ColorArg] Sketch::color(self : Sketch, color : C) -> Color

    Sketch::color_mode

    fn Sketch::color_mode(self : Sketch, mode : ColorMode) -> Unit

    Sketch::color_mode_max

    fn Sketch::color_mode_max(self : Sketch, mode : ColorMode, maximum : Double) -> Unit

    Sketch::color_mode_maxes

    fn Sketch::color_mode_maxes(self : Sketch, mode : ColorMode, c0 : Double, c1 : Double, c2 : Double, alpha? : Double) -> Unit

    Sketch::composition_end

    fn Sketch::composition_end(self : Sketch, text : String) -> Unit

    Ends composition with the committed text. The preedit is cleared and the text is recorded in last_input_text.

    Sketch::composition_start

    fn Sketch::composition_start(self : Sketch) -> Unit

    Starts an IME composition. composition_text becomes the empty preedit.

    Sketch::composition_update

    fn Sketch::composition_update(self : Sketch, text : String) -> Unit

    Updates the active preedit. composing stays true.

    Sketch::cos

    fn Sketch::cos(self : Sketch, angle : Double) -> Double

    Sketch::create_graphics

    fn Sketch::create_graphics(self : Sketch, width : Int, height : Int) -> Sketch

    Creates a vector graphics buffer. It is a normal Sketch with a recording surface: draw with rect/text/circle/..., then pass it to image() to replay it onto another sketch.

    Sketch::create_image

    fn Sketch::create_image(self : Sketch, width : Int, height : Int) -> Image

    Creates an empty image / graphics buffer, like p5's createImage and the pixel-buffer subset of createGraphics.

    Sketch::create_vector

    fn Sketch::create_vector(self : Sketch, x : Double, y : Double, z? : Double) -> Vector

    Sketch::curve

    fn Sketch::curve(self : Sketch, x1 : Double, y1 : Double, x2 : Double, y2 : Double, x3 : Double, y3 : Double, x4 : Double, y4 : Double) -> Unit

    Sketch::curve_tightness

    fn Sketch::curve_tightness(self : Sketch, tightness : Double) -> Unit

    Sketch::curve_vertex

    fn Sketch::curve_vertex(self : Sketch, x : Double, y : Double) -> Unit

    Alias for spline_vertex, matching p5's curveVertex.

    Sketch::draw

    fn Sketch::draw(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Installs the draw callback (run once per frame).

    Sketch::draw_as_image

    fn Sketch::draw_as_image(self : Sketch, target : Sketch, x : Double, y : Double, width : Double, height : Double) -> Unit

    Sketch::ellipse

    fn Sketch::ellipse(self : Sketch, x : Double, y : Double, width : Double, height? : Double) -> Unit

    Sketch::ellipse_mode

    fn Sketch::ellipse_mode(self : Sketch, mode : ShapeMode) -> Unit

    Sketch::end_contour

    fn Sketch::end_contour(self : Sketch, close? : Bool) -> Unit

    Ends the current subpath. close=true appends Close; the next contour starts with a fresh MoveTo either way.

    Sketch::end_shape

    fn Sketch::end_shape(self : Sketch, close? : Bool) -> Unit

    Sketch::file_ports

    fn Sketch::file_ports(self : Sketch) -> FilePorts

    The byte I/O this sketch routes image loading and saving through.

    Sketch::fill

    fn[C : ColorArg] Sketch::fill(self : Sketch, color : C) -> Unit

    Sketch::focus_changed

    fn Sketch::focus_changed(self : Sketch, focused : Bool) -> Unit

    Sketch::frame

    fn Sketch::frame(self : Sketch, now_ms : Double) -> Bool

    Advances and draws one frame. now_ms is the host clock in milliseconds.

    The first call runs setup and then draw. When the host repaints without advancing its clock, the frame counter is not advanced and draw only runs if a redraw was requested (so input remains responsive without double stepping time-based animation).

    Sketch::frame_rate

    fn Sketch::frame_rate(self : Sketch, value : Double) -> Unit

    Sketch::get_angle_mode

    fn Sketch::get_angle_mode(self : Sketch) -> AngleMode

    Sketch::get_color_mode

    fn Sketch::get_color_mode(self : Sketch) -> ColorMode

    Sketch::get_fill

    fn Sketch::get_fill(self : Sketch) -> Color?

    Sketch::get_frame_rate

    fn Sketch::get_frame_rate(self : Sketch) -> Double

    Sketch::get_matrix

    fn Sketch::get_matrix(self : Sketch) -> Matrix

    Sketch::get_stroke

    fn Sketch::get_stroke(self : Sketch) -> Color?

    Sketch::get_text_leading

    fn Sketch::get_text_leading(self : Sketch) -> Double

    Sketch::get_text_size

    fn Sketch::get_text_size(self : Sketch) -> Double

    Sketch::green

    fn[C : ColorArg] Sketch::green(self : Sketch, color : C) -> Double

    Sketch::hue

    fn[C : ColorArg] Sketch::hue(self : Sketch, color : C) -> Double

    Sketch::image

    fn[T : ImageSource] Sketch::image(self : Sketch, source : T, x : Double, y : Double, width? : Double, height? : Double) -> Unit

    Draws an image or graphics buffer at (x, y). Width/height default to the source size.

    Sketch::image_size

    fn Sketch::image_size(self : Sketch) -> (Double, Double)

    Sketch::is_looping

    fn Sketch::is_looping(self : Sketch) -> Bool

    Sketch::key_down

    fn Sketch::key_down(self : Sketch, key : String, code? : String, key_code? : Int) -> Unit

    Sketch::key_is_down

    fn Sketch::key_is_down(self : Sketch, key : String) -> Bool

    Sketch::key_typed_input

    fn Sketch::key_typed_input(self : Sketch, key : String) -> Unit

    Sketch::key_up

    fn Sketch::key_up(self : Sketch, key : String, code? : String, key_code? : Int) -> Unit

    Sketch::lerp_color

    fn Sketch::lerp_color(self : Sketch, from : Color, to : Color, amount : Double) -> Color

    Sketch::lightness

    fn[C : ColorArg] Sketch::lightness(self : Sketch, color : C) -> Double

    Sketch::line

    fn Sketch::line(self : Sketch, x1 : Double, y1 : Double, x2 : Double, y2 : Double) -> Unit

    Sketch::load_image

    fn Sketch::load_image(self : Sketch, source : String, on_load? : (Image) -> Unit) -> Image

    Synchronous load_image. Decodes PNG data URIs and local PNG files; other sources fall back to a 1x1 transparent placeholder, matching p5's "always return an image" contract. Use try_load_image to detect failure.

    Sketch::load_image_async

    fn Sketch::load_image_async(self : Sketch, source : String, on_load? : (Image) -> Unit) -> Image

    Non-blocking load_image. Data URIs and local files decode synchronously. For other sources the sketch returns a 1x1 transparent placeholder immediately and hands the source to the installed ImageFetcher; when the host completes with PNG bytes, the placeholder is filled in place and on_load receives that same image object. A failed fetch or decode leaves the placeholder untouched and still calls on_load, so callers can poll image.width() > 1 or keep their own state.

    The completion must run on the host's event loop (the same thread that owns the sketch). p5 marks the sketch for a redraw; a looping view presents it on the next frame, while a paused (no_loop) app should also trigger its own repaint from on_load.

    Sketch::loop_

    fn Sketch::loop_(self : Sketch) -> Unit

    Sketch::millis

    fn Sketch::millis(self : Sketch) -> Double

    Sketch::new

    fn Sketch::new(surface : &Surface, width : Double, height : Double, file_ports? : FilePorts) -> Sketch

    Sketch::no_fill

    fn Sketch::no_fill(self : Sketch) -> Unit

    Sketch::no_loop

    fn Sketch::no_loop(self : Sketch) -> Unit

    Sketch::no_smooth

    fn Sketch::no_smooth(self : Sketch) -> Unit

    Sketch::no_stroke

    fn Sketch::no_stroke(self : Sketch) -> Unit

    Sketch::no_tint

    fn Sketch::no_tint(self : Sketch) -> Unit

    Sketch::noise

    fn Sketch::noise(self : Sketch, x : Double, y? : Double, z? : Double) -> Double

    Sketch::noise_detail

    fn Sketch::noise_detail(self : Sketch, octaves : Int, falloff? : Double) -> Unit

    Sketch::noise_seed

    fn Sketch::noise_seed(self : Sketch, seed : Double) -> Unit

    Sketch::on_composition_end

    fn Sketch::on_composition_end(self : Sketch, callback : (Sketch, String) -> Unit) -> Unit

    Sketch::on_composition_start

    fn Sketch::on_composition_start(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_composition_update

    fn Sketch::on_composition_update(self : Sketch, callback : (Sketch, String) -> Unit) -> Unit

    Sketch::on_double_clicked

    fn Sketch::on_double_clicked(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_key_pressed

    fn Sketch::on_key_pressed(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_key_released

    fn Sketch::on_key_released(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_key_typed

    fn Sketch::on_key_typed(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_mouse_clicked

    fn Sketch::on_mouse_clicked(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_mouse_dragged

    fn Sketch::on_mouse_dragged(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_mouse_moved

    fn Sketch::on_mouse_moved(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_mouse_pressed

    fn Sketch::on_mouse_pressed(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_mouse_released

    fn Sketch::on_mouse_released(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_mouse_wheel

    fn Sketch::on_mouse_wheel(self : Sketch, callback : (Sketch, Double) -> Unit) -> Unit

    Sketch::on_text_input

    fn Sketch::on_text_input(self : Sketch, callback : (Sketch, String) -> Unit) -> Unit

    Called for committed text input (InsertText/ReplaceText), with the inserted text. The sketch is not required to be composing.

    Sketch::on_touch_ended

    fn Sketch::on_touch_ended(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_touch_moved

    fn Sketch::on_touch_moved(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::on_touch_started

    fn Sketch::on_touch_started(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Sketch::point

    fn Sketch::point(self : Sketch, x : Double, y : Double) -> Unit

    Sketch::point_vec

    fn Sketch::point_vec(self : Sketch, vector : Vector) -> Unit

    Sketch::pointer_clicked

    fn Sketch::pointer_clicked(self : Sketch, x : Double, y : Double) -> Unit

    Sketch::pointer_double_clicked

    fn Sketch::pointer_double_clicked(self : Sketch, x : Double, y : Double) -> Unit

    Sketch::pointer_down

    fn Sketch::pointer_down(self : Sketch, x : Double, y : Double, button? : Int) -> Unit

    Primary-button press at local sketch coordinates.

    Sketch::pointer_move

    fn Sketch::pointer_move(self : Sketch, x : Double, y : Double) -> Unit

    Sketch::pointer_up

    fn Sketch::pointer_up(self : Sketch, x : Double, y : Double) -> Unit

    Sketch::pointer_wheel

    fn Sketch::pointer_wheel(self : Sketch, delta : Double) -> Unit

    Sketch::pop

    fn Sketch::pop(self : Sketch) -> Unit

    Sketch::push

    fn Sketch::push(self : Sketch) -> Unit

    Sketch::quad

    fn Sketch::quad(self : Sketch, x1 : Double, y1 : Double, x2 : Double, y2 : Double, x3 : Double, y3 : Double, x4 : Double, y4 : Double) -> Unit

    Sketch::quadratic_vertex

    fn Sketch::quadratic_vertex(self : Sketch, cx : Double, cy : Double, x : Double, y : Double) -> Unit

    Sketch::random

    fn Sketch::random(self : Sketch) -> Double

    Sketch::random2d

    fn Sketch::random2d(self : Sketch) -> Vector

    Sketch::random3d

    fn Sketch::random3d(self : Sketch) -> Vector

    Sketch::random_choice

    fn[T] Sketch::random_choice(self : Sketch, choices : ArrayView[T]) -> T

    Sketch::random_gaussian

    fn Sketch::random_gaussian(self : Sketch, mean? : Double, sd? : Double) -> Double

    Sketch::random_max

    fn Sketch::random_max(self : Sketch, maximum : Double) -> Double

    Sketch::random_range

    fn Sketch::random_range(self : Sketch, minimum : Double, maximum : Double) -> Double

    Sketch::random_seed

    fn Sketch::random_seed(self : Sketch, seed : Double) -> Unit

    Sketch::rect

    fn Sketch::rect(self : Sketch, x : Double, y : Double, width : Double, height : Double, tl? : Double, tr? : Double, br? : Double, bl? : Double) -> Unit

    Sketch::rect_mode

    fn Sketch::rect_mode(self : Sketch, mode : ShapeMode) -> Unit

    Sketch::red

    fn[C : ColorArg] Sketch::red(self : Sketch, color : C) -> Double

    Sketch::redraw

    fn Sketch::redraw(self : Sketch, frames? : Int) -> Unit

    Sketch::request_redraw

    fn Sketch::request_redraw(self : Sketch, frames? : Int) -> Unit

    Sketch::reset_matrix

    fn Sketch::reset_matrix(self : Sketch) -> Unit

    Sketch::reset_sketch

    fn Sketch::reset_sketch(self : Sketch) -> Unit

    Resets the lifecycle (the next frame runs setup again) and restores the default drawing state.

    Sketch::resize_canvas

    fn Sketch::resize_canvas(self : Sketch, width : Double, height : Double) -> Unit

    Sketch::rotate

    fn Sketch::rotate(self : Sketch, angle : Double) -> Unit

    Sketch::saturation

    fn[C : ColorArg] Sketch::saturation(self : Sketch, color : C) -> Double

    Sketch::save_image

    fn Sketch::save_image(self : Sketch, image : Image, path : String) -> Bool

    Encodes image as a PNG and writes it through this sketch's FilePorts. Returns false when the ports reject the path. SketchView::save_canvas and host save() helpers route through here so image saving never reaches for a concrete filesystem.

    Sketch::scale

    fn Sketch::scale(self : Sketch, x : Double, y? : Double) -> Unit

    Sketch::set_file_ports

    fn Sketch::set_file_ports(self : Sketch, ports : FilePorts) -> Unit

    Replaces the host byte I/O used by try_load_image and save_image on this sketch. create_graphics copies the current ports to the child sketch; hosts usually install ports once with set_default_file_ports instead of calling this per sketch.

    Sketch::set_image_fetcher

    fn Sketch::set_image_fetcher(self : Sketch, fetcher : (String, (Bytes?) -> Unit) -> Unit) -> Unit

    Installs a host byte fetcher used by load_image_async when the source cannot be resolved synchronously (typically https:).

    Sketch::set_mouse_position

    fn Sketch::set_mouse_position(self : Sketch, x : Double, y : Double) -> Unit

    Places the cursor without firing a pointer callback. Useful in setup so the first frame already has a sensible hover position.

    Sketch::setup

    fn Sketch::setup(self : Sketch, callback : (Sketch) -> Unit) -> Unit

    Installs the setup callback (run once before the first draw).

    Sketch::shear_x

    fn Sketch::shear_x(self : Sketch, angle : Double) -> Unit

    Sketch::shear_y

    fn Sketch::shear_y(self : Sketch, angle : Double) -> Unit

    Sketch::sin

    fn Sketch::sin(self : Sketch, angle : Double) -> Double

    Sketch::smooth

    fn Sketch::smooth(self : Sketch) -> Unit

    Sketch::spline_tightness

    fn Sketch::spline_tightness(self : Sketch, tightness : Double) -> Unit

    Sets the Catmull-Rom tightness used by spline_vertex/curve_vertex (0 = Catmull-Rom).

    Sketch::spline_vertex

    fn Sketch::spline_vertex(self : Sketch, x : Double, y : Double) -> Unit

    Buffers a Catmull-Rom spline sample. Call end_shape/end_contour to flush; the first and last samples act as control points.

    Sketch::square

    fn Sketch::square(self : Sketch, x : Double, y : Double, size : Double, tl? : Double, tr? : Double, br? : Double, bl? : Double) -> Unit

    Sketch::stroke

    fn[C : ColorArg] Sketch::stroke(self : Sketch, color : C) -> Unit

    Sketch::stroke_cap

    fn Sketch::stroke_cap(self : Sketch, cap : StrokeCap) -> Unit

    Sketch::stroke_join

    fn Sketch::stroke_join(self : Sketch, join : StrokeJoin) -> Unit

    Sketch::stroke_weight

    fn Sketch::stroke_weight(self : Sketch, weight : Double) -> Unit

    Sketch::tan

    fn Sketch::tan(self : Sketch, angle : Double) -> Double

    Sketch::text

    fn Sketch::text(self : Sketch, content : String, x : Double, y : Double, max_width? : Double, max_height? : Double) -> Unit

    Draws text. x/y are interpreted through text_align and text_size/text_leading. Newlines are always honored; max_width additionally wraps by words (or characters under TextWrap::Char).

    Sketch::text_align

    fn Sketch::text_align(self : Sketch, horizontal : HAlign, vertical? : VAlign) -> Unit

    Sketch::text_ascent

    fn Sketch::text_ascent(self : Sketch) -> Double

    Sketch::text_descent

    fn Sketch::text_descent(self : Sketch) -> Double

    Sketch::text_font

    fn Sketch::text_font(self : Sketch, family : String, size? : Double) -> Unit

    Sketch::text_input

    fn Sketch::text_input(self : Sketch, text : String) -> Unit

    Reports committed text input (IME commit or direct typing).

    Sketch::text_leading

    fn Sketch::text_leading(self : Sketch, leading : Double) -> Unit

    Sketch::text_size

    fn Sketch::text_size(self : Sketch, size : Double) -> Unit

    Sketch::text_style

    fn Sketch::text_style(self : Sketch, style : TextStyle) -> Unit

    Sketch::text_width

    fn Sketch::text_width(self : Sketch, content : String) -> Double

    Sketch::text_wrap

    fn Sketch::text_wrap(self : Sketch, mode : TextWrap) -> Unit

    Sketch::tint

    fn[C : ColorArg] Sketch::tint(self : Sketch, color : C) -> Unit

    Multiplies subsequent image draws by color (p5 tint).

    Sketch::touch_ended_at

    fn Sketch::touch_ended_at(self : Sketch, id : Int) -> Unit

    Ends one contact. The ended contact is removed before the callback, matching p5's touches view inside touchEnded.

    Sketch::touch_moved_to

    fn Sketch::touch_moved_to(self : Sketch, id : Int, x : Double, y : Double, pressure? : Double) -> Unit

    Moves one contact. A Move for an unknown id is treated as a start so a host that drops the initial Down still reports a usable contact.

    Sketch::touch_started_at

    fn Sketch::touch_started_at(self : Sketch, id : Int, x : Double, y : Double, pressure? : Double) -> Unit

    Begins (or restarts) a pointer contact. The same id updates one entry in touches; pressure is clamped to 0..1 and defaults to 1.0 ("no host pressure signal"). The callback reads the committed p.touches.

    Sketch::translate

    fn Sketch::translate(self : Sketch, x : Double, y : Double) -> Unit

    Sketch::triangle

    fn Sketch::triangle(self : Sketch, x1 : Double, y1 : Double, x2 : Double, y2 : Double, x3 : Double, y3 : Double) -> Unit

    Sketch::try_load_image

    fn Sketch::try_load_image(self : Sketch, source : String) -> Image?

    Loads a PNG image from a data:image/png;base64, URI, a local file path, or a file:// path. Returns None when the source is unsupported, cannot be read through this sketch's FilePorts, or does not decode as an 8-bit non-interlaced PNG.

    HTTP(S) URLs are intentionally not fetched here: synchronous host I/O would block the frame. Hosts that need URL loading should download the bytes and call Image::from_png_bytes, or wire an async loader at the app layer.

    Local paths are read through the ports injected at construction time (or installed with set_default_file_ports), so the addon itself never depends on a concrete filesystem.

    Sketch::vertex

    fn Sketch::vertex(self : Sketch, x : Double, y : Double) -> Unit

    StrokeCap

    pub(all) enum StrokeCap {
    Round
    Square
    Project
    } derive(Eq)

    StrokeCap::equal

    fn StrokeCap::equal(StrokeCap, StrokeCap) -> Bool
    automatically derived

    StrokeCap::not_equal

    fn StrokeCap::not_equal(x : StrokeCap, y : StrokeCap) -> Bool
    automatically derived

    StrokeJoin

    pub(all) enum StrokeJoin {
    Miter
    Bevel
    RoundJoin
    } derive(Eq)

    StrokeJoin::equal

    fn StrokeJoin::equal(StrokeJoin, StrokeJoin) -> Bool
    automatically derived

    StrokeJoin::not_equal

    fn StrokeJoin::not_equal(x : StrokeJoin, y : StrokeJoin) -> Bool
    automatically derived

    TextMetrics

    pub(all) struct TextMetrics {
    width : Double
    height : Double
    ascent : Double
    descent : Double
    } derive(Eq)

    TextMetrics::equal

    fn TextMetrics::equal(TextMetrics, TextMetrics) -> Bool
    automatically derived

    TextMetrics::new

    fn TextMetrics::new(width~ : Double, height~ : Double, ascent~ : Double, descent~ : Double) -> TextMetrics

    TextMetrics::not_equal

    fn TextMetrics::not_equal(x : TextMetrics, y : TextMetrics) -> Bool
    automatically derived

    TextStyle

    pub(all) enum TextStyle {
    Normal
    Italic
    Bold
    BoldItalic
    } derive(Eq)

    TextStyle::equal

    fn TextStyle::equal(TextStyle, TextStyle) -> Bool
    automatically derived

    TextStyle::not_equal

    fn TextStyle::not_equal(x : TextStyle, y : TextStyle) -> Bool
    automatically derived

    TextWrap

    pub(all) enum TextWrap {
    Word
    Char
    } derive(Eq)

    TextWrap::equal

    fn TextWrap::equal(TextWrap, TextWrap) -> Bool
    automatically derived

    TextWrap::not_equal

    fn TextWrap::not_equal(x : TextWrap, y : TextWrap) -> Bool
    automatically derived

    Touch

    pub(all) struct Touch {
    x : Double
    y : Double
    win_x : Double
    win_y : Double
    id : Int
    pressure : Double
    } derive(Eq)

    One active pointer contact. MoUI exposes pointer stream identity and normalized pressure; p5-style touches use the same id for the lifetime of a contact. win_x/win_y are canvas-local in this adapter (MoUI input is already local to the hit element).

    Touch::equal

    fn Touch::equal(Touch, Touch) -> Bool
    automatically derived

    Touch::new

    fn Touch::new(x~ : Double, y~ : Double, id~ : Int, pressure? : Double) -> Touch

    Touch::not_equal

    fn Touch::not_equal(x : Touch, y : Touch) -> Bool
    automatically derived

    VAlign

    pub(all) enum VAlign {
    Top
    VCenter
    Bottom
    Baseline
    } derive(Eq)

    VAlign::equal

    fn VAlign::equal(VAlign, VAlign) -> Bool
    automatically derived

    VAlign::not_equal

    fn VAlign::not_equal(x : VAlign, y : VAlign) -> Bool
    automatically derived

    Vector

    pub struct Vector {
    x : Double
    y : Double
    z : Double
    }

    p5-style 2D/3D vector. Mutating methods return Unit; copy returns a new vector.

    Vector::add

    fn Vector::add(self : Vector, other : Vector) -> Unit

    Vector::angle_between

    fn Vector::angle_between(self : Vector, other : Vector) -> Double

    Vector::array

    fn Vector::array(self : Vector) -> Array[Double]

    Vector::copy

    fn Vector::copy(self : Vector) -> Vector

    Vector::cross

    fn Vector::cross(self : Vector, other : Vector) -> Vector

    Vector::dist

    fn Vector::dist(self : Vector, other : Vector) -> Double

    Vector::div

    fn Vector::div(self : Vector, scalar : Double) -> Unit

    Vector::dot

    fn Vector::dot(self : Vector, other : Vector) -> Double

    Vector::heading

    fn Vector::heading(self : Vector) -> Double

    Vector::lerp

    fn Vector::lerp(self : Vector, other : Vector, amount : Double) -> Unit

    Vector::limit

    fn Vector::limit(self : Vector, maximum : Double) -> Unit

    Vector::mag

    fn Vector::mag(self : Vector) -> Double

    Vector::mag_sq

    fn Vector::mag_sq(self : Vector) -> Double

    Vector::mult

    fn Vector::mult(self : Vector, scalar : Double) -> Unit

    Vector::new

    fn Vector::new(x? : Double, y? : Double, z? : Double) -> Vector

    Vector::normalize

    fn Vector::normalize(self : Vector) -> Unit

    Vector::rotate

    fn Vector::rotate(self : Vector, angle : Double) -> Unit

    Vector::set

    fn Vector::set(self : Vector, x : Double, y : Double, z? : Double) -> Unit

    Vector::set_mag

    fn Vector::set_mag(self : Vector, length : Double) -> Unit

    Vector::sub

    fn Vector::sub(self : Vector, other : Vector) -> Unit

    DEG_TO_RAD

    let DEG_TO_RAD : Double

    HALF_PI

    let HALF_PI : Double

    let PI : Double

    QUARTER_PI

    let QUARTER_PI : Double

    RAD_TO_DEG

    let RAD_TO_DEG : Double

    TAU

    let TAU : Double

    TWO_PI

    let TWO_PI : Double

    clear_default_file_ports

    fn clear_default_file_ports() -> Unit

    Removes the installed ports; later sketches inherit FilePorts::none.

    color_from_values

    fn color_from_values(values : ArrayView[Double], mode : ColorMode, ranges : ColorRanges) -> Color

    Converts user values in mode/ranges into a normalized sRGB color.

    constrain

    fn constrain(value : Double, low : Double, high : Double) -> Double

    default_color_ranges

    fn default_color_ranges(mode : ColorMode) -> ColorRanges

    default_file_ports

    fn default_file_ports() -> FilePorts

    The ports installed with set_default_file_ports, or FilePorts::none.

    degrees

    fn degrees(radians : Double) -> Double

    dist

    fn dist(x1 : Double, y1 : Double, x2 : Double, y2 : Double) -> Double

    dist3

    fn dist3(x1 : Double, y1 : Double, z1 : Double, x2 : Double, y2 : Double, z2 : Double) -> Double

    fract

    fn fract(value : Double) -> Double

    Fractional part with p5/JavaScript semantics (fract(-1.25) == 0.75).

    hsb_to_rgb

    fn hsb_to_rgb(hue : Double, saturation : Double, brightness : Double, alpha : Double) -> Color

    hsl_to_rgb

    fn hsl_to_rgb(hue : Double, saturation : Double, lightness : Double, alpha : Double) -> Color

    js_round

    fn js_round(value : Double) -> Double

    JavaScript Math.round: ties go toward positive infinity.

    lerp

    fn lerp(start : Double, stop : Double, amount : Double) -> Double

    mag

    fn mag(x : Double, y : Double) -> Double

    map

    fn map(value : Double, start1 : Double, stop1 : Double, start2 : Double, stop2 : Double, within_bounds? : Bool) -> Double

    norm

    fn norm(value : Double, start : Double, stop : Double) -> Double

    parse_color

    fn parse_color(text : String) -> Color?

    Parses #rgb, #rgba, #rrggbb, #rrggbbaa, and a useful subset of CSS named colors.

    radians

    fn radians(degrees : Double) -> Double

    round

    fn round(value : Double, decimals? : Int) -> Double

    set_default_file_ports

    fn set_default_file_ports(ports : FilePorts) -> Unit

    Installs the ports inherited by sketches created after this call.

    set_default_image_fetcher

    fn set_default_image_fetcher(fetcher : (String, (Bytes?) -> Unit) -> Unit?) -> Unit

    Installs the fetcher inherited by sketches created after this call. Native app entrypoints use it to route https: sources through an async worker without threading a fetcher through every Sketch::new call site.
    fn sq(value : Double) -> Double

    to_uint32

    fn to_uint32(value : Double) -> UInt