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:
1
/// A trait for types which paint canvases.
2
pub trait Artist: Sized {
3
/// Constructs the artist.
4
///
5
/// This would be a place to compile any GLSL or construct any expensive
6
/// resources needed across the whole composition.
7
fn setup(gpu: Gpu, world: World, rng: &mut StdRng) -> Result<Self>;
8
​
9
/// Paints a single frame.
10
fn paint(&mut self, ctx: Context, canvas: &mut Canvas);
11
}
Copied!
To run a drawing, call
1
run::<YourArtistType>(Options::from_args())
Copied!
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:
1
run_fn(Options::from_args(), |gpu, world, rng| {
2
Ok(move |ctx: Context, canvas: &mut Canvas| {
3
// Paint frames here
4
})
5
})
Copied!
The full command line interface:
1
Command line options for a painting run.
2
​
3
Construct with `Options::from_args()` to run the CLI.
4
​
5
USAGE:
6
simple [FLAGS] [OPTIONS]
7
​
8
FLAGS:
9
-b, --brainstorm
10
In brainstorm mode:
11
12
* When rendering a limited number of frames to screen, the preview
13
will not close.
14
15
* When rendering to file, every frame will be rendered with a
16
different seed.
17
--help
18
Prints help information
19
​
20
-V, --version
21
Prints version information
22
​
23
​
24
OPTIONS:
25
-d, --delay <delay>
26
The number of frames to delay saving to file. For example, if
27
delay=100, 100 frames will be rendered silently and then the 101st
28
and those after it will be saved to file. [default: 0]
29
-r, --frames_per_second <framerate>
30
The number of frames (to try) to render per second. [default: 24]
31
​
32
-f, --frames <frames>
33
The total number of frames in this painting.
34
​
35
-h, --height <height>
36
The height in coordinate space of the painting.
37
38
Coordinate space may differ from output space. If height is 500 but
39
scale is 10, the painting will have a coordinate space height of 500,
40
but the final output will have a height of 5000 pixels. [default: 650]
41
-o, --output <output>
42
Prefix of output path. Output is <prefix>/<seed>/<frame_number>.png
43
​
44
-s, --scale <scale>
45
The scale of the output.
46
47
The final output space is (width*scale)x(height*scale). This value is
48
useful for painting and doing work at one quickly rendering
49
resolution, and later exporting at a much higher resolution while
50
preserving the composition exactly.
51
52
This value may be needed when writing shaders or using other raster
53
graphics, to adjust them for the real output size. Vector painting
54
such as with paths should not need to consider this. [default: 1.0]
55
-e, --seed <seed>
56
The RNG seed for this painting. [default: 0]
57
​
58
-w, --width <width>
59
The width in coordinate space of the painting.
60
61
Coordinate space may differ from output space. If width is 500 but
62
scale is 10, the painting will have a coordinate space width of 500,
63
but the final output will have a width of 5000 pixels. [default: 512]
64
​
Copied!
Copy link