whiskers: interactive sketches for plotter generative art
👉 Try the live demo!
whiskers is a Processing-like interactive sketch environment and API built over vsvg and vsvg-viewer. It's similar to vsketch, but faster, web-ready, and with much stronger foundations.
Installation
Simply add whiskers as a dependency to your project:
cargo add whiskers
Usage
Here is the code for a basic sketch:
use *;
// <- this is the magic to make the sketch interactive
This is the result:
whiskers is part of the vsvg project.
Features
- Interactive UI automatically built based on the sketch
struct's fields. - Sketch parameter UI highly customisable using
#[param(...)]attributes (see e.g.asteroidexample). - Sketch parameter UI easily extendable for custom data types (see e.g.
custom_uiexample). - Page size management UI.
- Export to SVG.
- Support for curves (including quadratic Béziers, cubic Bézier, Catmull-Rom splines—circles, ellipses and arcs are supported but internally converted to cubic Bézier).
- Time parameter management UI (for animated sketches).
- Random Number Generator UI with seed control (see e.g.
asteroidexample). - Integrated profiler (based on puffin).
-
Gridhelper for grid-based sketches. -
HexGridhelper for hexagonal-grid-based sketches - Configuration handling (save/restore config, etc.).
- Compiled sketches are also a flexible CLI utility with the capability to batch generate sketch outputs with parameter ranges.
- Export to other format through templating (HPGL, g-code, etc. — for now, please use vpype).
- ... (please complete this list)
Isn't that vsketch?
Compared to vsketch, whiskers offers the following advantages:
- It's in Rust, so it's faaast! 🚀
- Sketches can be compiled to WebAssembly and published on the Web (try it here).
- It's built on a stack (mainly egui and wgpu) that's much faster and easier to work with.
On the other hand:
- It's in Rust, which has a steeper learning curve than Python.
- Since sketches are compiled, the edit code/execute cycle is heavier than with vsketch.
I have the vague dream to slap a Python front-end on top of whiskers to build vsketch 2.0, but that's a lot of work and other things have a higher priority, so no promises on this front.
Running examples
To run the example, use the following command (in this case to run crates/whiskers/examples/asteroid.rs):
cargo run --release --package whiskers --example asteroid
Non-interactive use
The whiskers::Sketch object can be used stand-alone, without the interactive sketch runner. This is useful if you want to use the drawing capabilities in your own tools.
For example, I use whiskers::Sketch to build the generative asteroids in my Rusteroïds toy game.
Here is how the code could look:
use *;
If the viewer feature of *whiskers is enabled (which it is by default), the sketch can be displayed using the basic viewer using sketch.show().