Crates.io | whiskers |
lib.rs | whiskers |
version | 0.5.0 |
source | src |
created_at | 2023-09-29 20:04:17.521479 |
updated_at | 2024-09-21 09:52:24.015901 |
description | Processing-like, interactive sketching environment for plotter generative art. |
homepage | https://github.com/abey79/vsvg |
repository | https://github.com/abey79/vsvg |
max_upload_size | |
id | 987828 |
size | 251,314 |
whiskers is a Rust interactive sketch environment for plotter generative art, with a Processing inspired API.
👉 Try the live demo!
It's similar to vsketch, but faster, web-ready, and with vsvg as a much stronger foundation.
Simply add whiskers as a dependency to your project:
cargo add whiskers
Here is the code for a basic sketch:
use whiskers::prelude::*;
#[sketch_app] // <- this is the magic to make the sketch interactive
struct HelloWorldSketch {
width: f64, // <- interactive UI is automagically built for these fields
height: f64,
}
impl Default for HelloWorldSketch {
fn default() -> Self {
Self {
width: 400.0,
height: 300.0,
}
}
}
impl App for HelloWorldSketch {
fn update(&mut self, sketch: &mut Sketch, _ctx: &mut Context) -> anyhow::Result<()> {
sketch.color(Color::DARK_RED).stroke_width(3.0);
// the `Sketch` API is a delight to work with
// this is where the drawing happens:
sketch
.translate(sketch.width() / 2.0, sketch.height() / 2.0)
.rect(0., 0., self.width, self.height);
Ok(())
}
}
fn main() -> Result {
HelloWorldSketch::runner()
.with_page_size_options(PageSize::A5H)
.run()
}
This is the result:
whiskers is a work in progress, but currently features:
asteroid
example).On top of all that, you can import other rust packages for features such as noise and boolean operations, for which you can use noise-rs
and geo
respectively (see examples noise
and astroids
).
Compared to vsketch, whiskers offers the following advantages:
On the other hand:
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.
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
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 whiskers::prelude::*;
fn main() -> Result {
Sketch::with_page_size_options(PageSize::A5)
.scale(Units::Cm)
.translate(7.0, 6.0)
.circle(0.0, 0.0, 2.5)
.translate(1.0, 4.0)
.rotate_deg(45.0)
.rect(0., 0., 4.0, 1.0)
.save("output.svg")?;
Ok(())
}
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()
.
This project is at an early the stage and needs your contribution. Please get in touch via discussions on GitHub or the DrawingBots’s Discord server if you feel like helping!