Being the Artist

Valora's runtime interface.

Valora provides a trait, Artist, which you must implement in order to draw. The trait looks like this:

/// A trait for types which paint canvases.
pub trait Artist: Sized {
    /// Constructs the artist.
    ///
    /// This would be a place to compile any GLSL or construct any expensive
    /// resources needed across the whole composition.
    fn setup(gpu: Gpu, world: World, rng: &mut StdRng) -> Result<Self>;

    /// Paints a single frame.
    fn paint(&mut self, ctx: Context, canvas: &mut Canvas);
}

To run a drawing, call

run::<YourArtistType>(Options::from_args())

Calling Options::from_args() will provide valora's command line interface, which is shown below. This is all you have to do! The rendering, saving to file, resolutions, seed, etc, can all be configured by the command line interface without any changes to code.

There is also a convenience implementation of Artist for functions that return painting functions, such as we used in the introduction:

run_fn(Options::from_args(), |gpu, world, rng| {
    Ok(move |ctx: Context, canvas: &mut Canvas| {
        // Paint frames here
    })
})

The full command line interface:

Last updated

Was this helpful?