2021-03-30 22:27:12 +02:00
|
|
|
//! Shows how to load svgs
|
|
|
|
|
|
|
|
use geo::rotate::RotatePoint;
|
|
|
|
use geo::translate::Translate;
|
|
|
|
use geo::{Coordinate, Point};
|
|
|
|
use polygon_art::Context;
|
2021-04-13 07:47:29 +02:00
|
|
|
use polygon_art::TranslateExt;
|
2021-04-13 20:24:04 +02:00
|
|
|
use polygon_art::{load_multipolygon_from_svg, ScaleExt};
|
2021-03-30 22:27:12 +02:00
|
|
|
use rand::Rng;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut renderer = Context::create();
|
|
|
|
|
|
|
|
let path = "pool/examples/example.svg";
|
2021-04-10 03:25:03 +02:00
|
|
|
let svg = load_multipolygon_from_svg(path).expect("couldn't load svg");
|
2021-03-30 22:27:12 +02:00
|
|
|
|
|
|
|
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,
|
|
|
|
);
|
2021-04-08 07:13:22 +02:00
|
|
|
renderer.draw_multipolygon(&svg);
|
2021-03-30 22:27:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
renderer.render();
|
|
|
|
}
|