Skip to main content

gradation/
gradation.rs

1use kanoko::{
2    Canvas, Color,
3    point_set::lattice::{Index, Lattice},
4    shape::Polygon,
5};
6
7/// An example where the shapes are varied depending on the index.
8fn main() {
9    let background_color = "#ddd".try_into().unwrap();
10    let mut canvas_builder = Canvas::builder()
11        .size(2560.0, 1440.0)
12        .background_color(background_color)
13        .points(
14            Lattice::rectangular_builder()
15                .grid_size(7, 5)
16                .len_a(300.0)
17                .len_b(200.0)
18                .build(),
19        );
20
21    canvas_builder.add_shape(
22        Polygon::builder()
23            .sides_fn(|Index { u, .. }| *u as u8 + 3)
24            .size_fn(|Index { v, .. }| *v as f64 * 35.0 + 80.0)
25            .color_fn(|Index { u, v }| Color::new((*u + 1) as u8 * 25, 0, (*v + 1) as u8 * 25, 255))
26            .build(),
27    );
28
29    let canvas = canvas_builder.build();
30    let document = canvas.render(|_| true);
31    svg::save("examples/gradation.svg", &document).unwrap();
32}