1use tiling::{Color, Model, Result, Shape};
2
3const WIDTH: i32 = 1024;
4const HEIGHT: i32 = 1024;
5const SCALE: f64 = 128.0;
6const MARGIN: f64 = 0.1;
7const SHOW_LABELS: bool = false;
8const LINE_WIDTH: f64 = 0.1;
9
10pub fn main() -> Result<()> {
11 let blue = Color::new(56, 103, 165)?;
12 let yellow = Color::new(242, 205, 21)?;
13 let gold = Color::new(242, 174, 45)?;
14 let orange = Color::new(216, 140, 73)?;
15 let burnt = Color::new(191, 86, 47)?;
16
17 Ex3636::render(blue, yellow, gold, orange, burnt)?;
18 Ex33434::render(blue, yellow, gold, orange, burnt)?;
19 Ex33336::render(blue, yellow, gold, orange, burnt)?;
20 Ex333333::render(blue, yellow, gold, orange, burnt)?;
21
22 Ok(())
23}
24
25trait Example {
26 fn render(
27 background: Color,
28 stroke: Color,
29 fill_0: Color,
30 fill_1: Color,
31 fill_2: Color,
32 ) -> Result<()>;
33}
34
35struct Ex3636();
36
37impl Example for Ex3636 {
38 fn render(
39 background: Color,
40 stroke: Color,
41 fill_0: Color,
42 fill_1: Color,
43 fill_2: Color,
44 ) -> Result<()> {
45 let mut model = Model::new(WIDTH, HEIGHT, SCALE);
46 model.add(Shape::new(6, fill_1, stroke)?);
47 let a = model.add_multi(0..1, 0..6, Shape::new(3, fill_0, stroke)?)?;
48 let b = model.add_multi(a, 1..2, Shape::new(6, fill_1, stroke)?)?;
49 model.repeat(b)?;
50
51 model
52 .render(background, MARGIN, LINE_WIDTH, SHOW_LABELS)?
53 .write_to_png("3.6.3.6.png")?;
54 model
55 .render_dual(background, fill_0, stroke, MARGIN, LINE_WIDTH)?
56 .write_to_png("3.6.3.6-dual.png")?;
57
58 Ok(())
59 }
60}
61
62struct Ex33434();
63
64impl Example for Ex33434 {
65 fn render(
66 background: Color,
67 stroke: Color,
68 fill_0: Color,
69 fill_1: Color,
70 fill_2: Color,
71 ) -> Result<()> {
72 let mut model = Model::new(WIDTH, HEIGHT, SCALE);
73 model.add(Shape::new(4, fill_1, stroke)?);
74 let a = model.add_multi(0..1, 0..4, Shape::new(3, fill_2, stroke)?)?;
75 let b = model.add_multi(a, 1..2, Shape::new(4, fill_1, stroke)?)?;
76 let c = model.add_multi(b, 2..4, Shape::new(3, fill_2, stroke)?)?;
77 let d = model.add_multi(c, 2..3, Shape::new(4, fill_1, stroke)?)?;
78 model.repeat(d)?;
79
80 model
81 .render(background, MARGIN, LINE_WIDTH, SHOW_LABELS)?
82 .write_to_png("3.3.4.3.4.png")?;
83 model
84 .render_dual(background, fill_0, stroke, MARGIN, LINE_WIDTH)?
85 .write_to_png("3.3.4.3.4-dual.png")?;
86
87 Ok(())
88 }
89}
90
91struct Ex33336();
92
93impl Example for Ex33336 {
94 fn render(
95 background: Color,
96 stroke: Color,
97 fill_0: Color,
98 fill_1: Color,
99 fill_2: Color,
100 ) -> Result<()> {
101 let mut model = Model::new(WIDTH, HEIGHT, SCALE);
102 model.add(Shape::new(6, fill_2, stroke)?);
103 let a = model.add_multi(0..1, 0..6, Shape::new(3, fill_0, stroke)?)?;
104 let b = model.add_multi(a.clone(), 1..2, Shape::new(3, fill_0, stroke)?)?;
105 let c = model.add_multi(a.clone(), 2..3, Shape::new(3, fill_0, stroke)?)?;
106 let d = model.add_multi(c, 1..2, Shape::new(6, fill_2, stroke)?)?;
107 model.repeat(d)?;
108
109 model
110 .render(background, MARGIN, LINE_WIDTH, SHOW_LABELS)?
111 .write_to_png("3.3.3.3.6.png")?;
112 model
113 .render_dual(background, fill_0, stroke, MARGIN, LINE_WIDTH)?
114 .write_to_png("3.3.3.3.6-dual.png")?;
115
116 Ok(())
117 }
118}
119
120struct Ex333333();
121
122impl Example for Ex333333 {
123 fn render(
124 background: Color,
125 stroke: Color,
126 fill_0: Color,
127 fill_1: Color,
128 fill_2: Color,
129 ) -> Result<()> {
130 let mut model = Model::new(WIDTH, HEIGHT, SCALE);
131 model.add(Shape::new(3, fill_2, stroke)?);
132 let a = model.add_multi(0..1, 0..3, Shape::new(3, fill_1, stroke)?)?;
133 let b = model.add_multi(a, 1..3, Shape::new(3, fill_2, stroke)?)?;
134 model.repeat(b)?;
135
136 model
137 .render(background, MARGIN, LINE_WIDTH, SHOW_LABELS)?
138 .write_to_png("3.3.3.3.3.3.png")?;
139 model
140 .render_dual(background, fill_0, stroke, MARGIN, LINE_WIDTH)?
141 .write_to_png("3.3.3.3.3.3-dual.png")?;
142
143 Ok(())
144 }
145}