Skip to content

Rust sketch API - #284

Draft
tychedelia wants to merge 4 commits into
processing:mainfrom
tychedelia:rust-api
Draft

tychedelia wants to merge 4 commits into
processing:mainfrom
tychedelia:rust-api

Conversation

@tychedelia

Copy link
Copy Markdown
Member

This adds a sketch API to the top-level processing crate, so a Rust sketch can look like a Processing sketch:

use processing::prelude::*;

struct MySketch;

impl Sketch for MySketch {
    fn settings() -> Settings {
        Settings::size(400, 400)
    }

    fn setup(_g: &mut Graphics) -> Result<Self> {
        Ok(MySketch)
    }

    fn draw(&mut self, g: &mut Graphics) {
        g.background(25);
        g.rect(g.mouse_x(), g.mouse_y(), 50, 50).radius(4);
    }
}

Some notes:

Functions with several signatures take tuples: fill(255), fill((255, 0, 0)), translate((x, y)). Optional arguments chain on the end, as with .radius() above.

Draw calls record straight away and return a small guard. The guard can still change the command it recorded until the next flush, where the engine tracks this with a command slot. push() and begin_shape() return guards that pop or end when they go out of scope. This is a style thing that we definitely can discuss more.

The engine re-exports that the bindings use moved from processing::prelude to processing::engine. prelude is now the sketch prelude. This is sa large mechanical change.

@tychedelia tychedelia changed the title Rust api Rust sketch API Nov 20, 2026
@github-actions

Copy link
Copy Markdown

Visual regression: 1 changed of 43 cases

case status detail
py_flocking_gpu ❌ changed 8% of pixels differ

If these changes are intentional, add the deliberate-rendering-change label.

baseline 1c92b8812a · adapter llvmpipe (LLVM 20.1.2, 256 bits) (Vulkan, Mesa 25.2.8-0ubuntu0.24.04.5 (LLVM 20.1.2))

Open the visual report · workflow run

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant