This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 2.8 kB View raw
1use shapemaker::CornerPoint as P; 2use shapemaker::*; 3 4pub fn shapes_shed() -> Canvas { 5 let mut canvas = Canvas::with_layers(vec![]); 6 7 canvas.set_grid_size(3, 3); 8 canvas.set_background(Color::White); 9 10 canvas.layer_unchecked("root").add_objects([ 11 BigCircle(P(0, 0)).colored(Black), 12 CurveOutward(P(1, 1), P(2, 0), 5.0).colored(Black), 13 CurveInward(P(2, 1), P(3, 0), 5.0).colored(Black), 14 SmallCircle(P(0, 1)).colored(Black), 15 Line(P(1, 1), P(2, 2), 5.0).colored(Black), 16 Rectangle(P(0, 2), P(0, 2)).colored(Black), 17 Dot(CenterPoint(1, 2)).colored(Black), 18 Polygon( 19 P(2, 1), 20 vec![ 21 LineSegment::Straight(P(3, 1)), 22 LineSegment::Straight(P(3, 2)), 23 ], 24 ) 25 .colored(Black), 26 CenteredText(P(2, 2), "Test".into(), 5.0).colored(Black), 27 ]); 28 29 canvas 30} 31 32pub fn colors_shed() -> Canvas { 33 let mut canvas = Canvas::with_layers(vec!["circles"]); 34 canvas.set_grid_size(3, 3); 35 canvas.outer_padding = 0; 36 canvas.set_background(Color::White); 37 38 let all_colors = vec![ 39 Color::Blue, 40 Color::Cyan, 41 Color::Yellow, 42 Color::Orange, 43 Color::Red, 44 Color::Brown, 45 Color::Purple, 46 Color::Pink, 47 Color::Green, 48 ]; 49 50 for (color, point) in std::iter::zip(all_colors, canvas.world_region) { 51 Shape::Rectangle(point, point) 52 .colored(color) 53 .add_to(canvas.root()); 54 } 55 56 canvas 57} 58 59pub fn grid() -> Canvas { 60 let mut canvas = Canvas::with_layers(vec![]); 61 canvas.set_grid_size(3, 3); 62 canvas.set_background(Color::White); 63 64 for point in canvas.world_region { 65 Shape::Dot(point) 66 .colored(Color::Black) 67 .add_to(canvas.root()); 68 } 69 70 canvas 71} 72 73fn main() { 74 grid() 75 .render_to_svg_file("grid.svg") 76 .expect("Failed to render grid"); 77 println!("Rendered grid.svg"); 78 colors_shed() 79 .render_to_svg_file("colorshed.svg") 80 .expect("Failed to render colors_shed"); 81 println!("Rendered colorshed.svg"); 82 shapes_shed() 83 .render_to_svg_file("shapeshed.svg") 84 .expect("Failed to render shapes_shed"); 85 println!("Rendered shapeshed.svg"); 86 shapes_shed() 87 .render_to_png("shapeshed.png", 1000) 88 .expect("Failed to render shapes_shed as PNG"); 89 println!("Rendered shapeshed.png"); 90} 91 92#[test] 93fn test_grid() { 94 use insta; 95 insta::assert_snapshot! { grid().render_to_svg_string().unwrap() } 96} 97 98#[test] 99fn test_colors_shed() { 100 use insta; 101 insta::assert_snapshot! { colors_shed().render_to_svg_string().unwrap() } 102} 103 104#[test] 105fn test_shapes_shed() { 106 use insta; 107 insta::assert_snapshot! { shapes_shed().render_to_svg_string().unwrap() } 108}