Your First Sketch
Sketch structure
Every sketch is a standalone Rust binary with two parts:
main()— configure the window (like Processing’ssetup()).draw()— called every frame.
use oripop_canvas::prelude::*;
fn main() {
size(800, 600);
title("my sketch");
smooth(4);
run(draw);
}
fn draw() {
background(20, 20, 30);
stroke(255, 200, 100);
stroke_weight(3.0);
line(100.0, 100.0, 700.0, 500.0);
}
Adding a new sketch
- Create
sketches/my-sketch.rswithfn main(). - Add a
[[bin]]entry insketches/Cargo.toml:
[[bin]]
name = "my-sketch"
path = "my-sketch.rs"
- Run it:
cargo run -p sketches --bin my-sketch
Coordinate system
- Origin is top-left (0, 0).
- x grows to the right.
- y grows downward.
- All values are in logical pixels (DPI-independent).