Struct Model

Source
pub struct Model { /* private fields */ }
Expand description

Represents a tiling composed of an arbitrary number of regular polygons. A model is used to imperatively construct a tiling by building small patterns of shapes that are then repeated to fill a two-dimensional space. Use render to render the tiling. Use render_dual to render the dual tiling.

Implementations§

Source§

impl Model

Source

pub fn new(width: i32, height: i32, scale: f64) -> Model

Returns an empty model.

Examples found in repository?
examples/examples.rs (line 45)
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    }
More examples
Hide additional examples
examples/intro.rs (line 17)
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}
Source

pub fn add(&mut self, shape: Shape)

Adds shape to the model.

Examples found in repository?
examples/examples.rs (line 46)
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    }
More examples
Hide additional examples
examples/intro.rs (line 20)
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}
Source

pub fn add_multi( &mut self, indexes: Range<usize>, edges: Range<usize>, shape: Shape, ) -> Result<Range<usize>>

Attaches shape to every edge in edges of each shape in indexes.

Examples found in repository?
examples/examples.rs (line 47)
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    }
More examples
Hide additional examples
examples/intro.rs (line 23)
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}
Source

pub fn repeat(&mut self, indexes: Range<usize>) -> Result<()>

Fills the rest of the surface with the pattern contained by the shapes with index in indexes.

Examples found in repository?
examples/examples.rs (line 49)
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    }
More examples
Hide additional examples
examples/intro.rs (line 32)
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}
Source

pub fn render( &self, background: Color, margin: f64, line_width: f64, show_labels: bool, ) -> Result<Render>

Renders the model.

Examples found in repository?
examples/examples.rs (line 52)
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    }
More examples
Hide additional examples
examples/intro.rs (line 35)
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}
Source

pub fn render_dual( &self, background: Color, fill: Color, stroke: Color, margin: f64, line_width: f64, ) -> Result<Render>

Renders the model’s dual tiling.

Examples found in repository?
examples/examples.rs (line 55)
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    }
More examples
Hide additional examples
examples/intro.rs (line 39)
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}

Trait Implementations§

Source§

impl Debug for Model

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Model

§

impl RefUnwindSafe for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnwindSafe for Model

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.