intro/
intro.rs

1use tiling::{Color, Model, Result, Shape};
2
3pub fn main() -> Result<()> {
4    let width = 1024;
5    let height = 1024;
6    let scale = 128.0;
7    let stroke = Color::new(242, 60, 60)?;
8    let fill_hexagon = Color::new(242, 194, 106)?;
9    let fill_square = Color::new(23, 216, 146)?;
10    let fill_triangle = Color::new(242, 209, 48)?;
11    let background = Color::new(242, 242, 242)?;
12    let margin = 0.1;
13    let show_labels = false;
14    let line_width = 0.1;
15
16    // create an empty model
17    let mut model = Model::new(width, height, scale);
18
19    // add a hexagon
20    model.add(Shape::new(6, fill_hexagon, stroke)?);
21
22    // attach a square to each side of the hexagon
23    let squares = model.add_multi(0..1, 0..6, Shape::new(4, fill_square, stroke)?)?;
24
25    // attach a triangle between the squares
26    let _ = model.add_multi(squares.clone(), 1..2, Shape::new(3, fill_triangle, stroke)?)?;
27
28    // attach a hexagon to the outer edge of each square
29    let hexagons = model.add_multi(squares.clone(), 2..3, Shape::new(6, fill_hexagon, stroke)?)?;
30
31    // fill the surface with the pattern
32    model.repeat(hexagons)?;
33
34    // render the tiling
35    let render = model.render(background, margin, line_width, show_labels)?;
36    render.write_to_png("intro.png")?;
37
38    // render the dual tiling
39    let render_dual = model.render_dual(background, fill_hexagon, stroke, margin, line_width)?;
40    render_dual.write_to_png("intro-dual.png")?;
41
42    Ok(())
43}