//! Shows how to load svgs use geo::rotate::RotatePoint; use geo::translate::Translate; use geo::{Coordinate, Point}; use polygon_art::load_multipolygon_from_svg; use polygon_art::Context; use polygon_art::MultiPolygonExt; use rand::Rng; fn main() { let mut renderer = Context::create(); let path = "pool/examples/example.svg"; let svg = load_multipolygon_from_svg(path).expect("couldn't load svg"); let item_space = 110.; let items_per_line = (renderer.width / item_space) as i32; let rows = (renderer.height / item_space) as i32; let items_to_draw = rows * items_per_line; let rotations: i32 = renderer.pseudo_random_number_generator.gen_range(0..10); let rotation_step = rotations as f64 * 360. / (items_to_draw as f64); let initial_transition_x = (renderer.width - items_per_line as f64 * item_space) / 2. + item_space / 2.; let initial_transition_y = (renderer.height - rows as f64 * item_space) / 2. + item_space / 2.; renderer.translate(initial_transition_x, initial_transition_y); let svg = svg.scale_to_width(item_space - (item_space * 0.1)); let svg = svg.translate_center(); for index in 0..items_to_draw { let svg = svg.rotate_around_point( index as f64 * rotation_step, Point(Coordinate { x: 0.0, y: 0.0 }), ); let svg = svg.translate( (index % items_per_line) as f64 * item_space, (index / items_per_line) as f64 * item_space, ); renderer.draw_multipolygon(&svg); } renderer.render(); }