context_basic/
context_basic.rs1use aoer_plotty_rs::geo_types::svg::Arrangement;
2use aoer_plotty_rs::prelude::NoHatch;
3use aoer_plotty_rs::{context::Context, prelude::LineHatch};
4use geo_types::{coord, Rect};
5use std::path::Path;
6use std::sync::Arc;
7
8fn main() {
9 let mut ctx = Context::new();
10 ctx.stroke("black")
11 .fill("red")
12 .pen(0.5)
13 .outline(Some(5.0))
14 .hatch(45.0)
15 .poly(
16 vec![(0.0, 0.0), (25.0, 0.0), (25.0, 25.0), (0.0, 25.0)],
17 vec![],
18 )
19 .outline(None)
20 .pattern(Arc::new(Box::new(LineHatch {})))
21 .hatch(135.0)
22 .stroke("blue")
23 .fill("yellow")
24 .circle(12.5, 12.5, 5.0)
25 .push()
26 .hatch(180.0)
27 .stroke("red")
28 .fill("green")
29 .circle(17.5, 12.5, 2.5)
30 .pop()
31 .unwrap()
32 .hatch(0.0)
33 .pattern(Arc::new(Box::new(LineHatch {})))
34 .clip(true)
35 .circle(7.5, 12.5, 2.5)
36 .clip(false)
37 .stroke("brown")
38 .pen(1.0)
39 .line(0.0, 0.0, 3.0, 3.0)
40 .pen(0.1)
41 .outline(Some(1.0))
42 .stroke("pink")
43 .line(3.0, 0.0, 0.0, 3.0)
44 .stroke("purple")
45 .spline(
46 &vec![
47 (0.0, 25.0),
48 (0.0, 25.0),
49 (10.0, 20.0),
50 (20.0, 25.0),
51 (25.0, 25.0),
52 ],
53 8,
54 0.5,
55 )
56 .push() .transform(Some(
58 &(Context::translate_matrix(25.0, 25.0)
59 * Context::rotate_matrix(45.0)
60 * Context::scale_matrix(1.0, 0.5)),
61 )) .stroke("cyan")
63 .circle(0.0, 0.0, 8.0)
64 .pop()
65 .unwrap() .outline(None)
67 .stroke("green")
68 .regular_poly(8, 80.0, 80.0, 20.0, 0.0)
69 .star_poly(5, 30.0, 80.0, 10.0, 20.0, 0.0)
70 .transform(Some(
71 &(Context::translate_matrix(50.0, 50.0) * Context::scale_matrix(0.02, -0.02)),
72 ))
73 .pattern(Arc::new(Box::new(NoHatch {})))
74 .pattern(Arc::new(Box::new(LineHatch {})))
75 .glyph('Q', false);
76
77 let svg = ctx
78 .to_svg(&Arrangement::<f64>::unit(&Rect::<f64>::new(
79 coord! {x:0.0, y:0.0},
80 coord! {x:100.0, y:100.0},
81 )))
82 .unwrap();
83 let fname = Path::new(file!()).file_stem().unwrap().to_str().unwrap();
86 svg::save(format!("images/{}.svg", fname), &svg).unwrap();
87}