diff --git a/Cargo.toml b/Cargo.toml index 48d30dc..a17c6a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ version = "1.0.0" authors = ["Ingolf Wagner "] edition = "2018" - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html description = "Convenience library to use geo to create art." documentation = "https://github.com/mrVanDalo/polygon-art" diff --git a/README.md b/README.md index df8f8cb..26b1db1 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,15 @@ Convenience library to create art using [geo](https://georust.org/). * load SVGs * scaling -# Asteroids +# Binaries + +I deliver some binaries to give you an impression and ideas +for your own images. + +All binaries created by polygon art have the same +command line interface. + +## Asteroids asteroids is an example binary which renders an image inspired by the @@ -14,11 +22,11 @@ image inspired by the ![image](./images/asteroids.png) -run `asteroids --help` to get information. -All binaries created by polygon art have the same -command line interface. +## Rings -# How to run examples +![image](./images/rings.png) + +# How to run /examples ``` cargo run --example clipping -- --help # run the examples/clipping diff --git a/images/rings.png b/images/rings.png new file mode 100644 index 0000000..427b4a7 Binary files /dev/null and b/images/rings.png differ diff --git a/src/bin/rings.rs b/src/bin/rings.rs new file mode 100644 index 0000000..a0b253e --- /dev/null +++ b/src/bin/rings.rs @@ -0,0 +1,55 @@ +use geo::algorithm::rotate::{Rotate, RotatePoint}; +use geo::algorithm::translate::Translate; +use geo::{polygon, Coordinate, MultiPolygon, Point}; +use geo_clipper::Clipper; +use polygon_art::{Context, MergeExt, TranslateExt}; +use rand::prelude::StdRng; +use rand::Rng; + +fn main() { + let mut context = Context::create(); + context.translate_center(); + + let min = f64::min(context.width, context.height); + let number_of_rings = (min / 150.) as i32; + + let mut radius = min / 2. - 5.; + for _ in 0..number_of_rings { + let ring_size = context.gen_rng().gen_range(10..(radius as i32 / 5)) as f64; + radius = radius - ring_size; + if radius < 10. { + break; + } + let polygons = generate_ring(&mut context.gen_rng(), radius, ring_size); + radius = radius - ring_size; + context.draw_multipolygon(&polygons); + } + + context.render(); +} + +fn generate_ring(rng: &mut StdRng, radius: f64, ring_size: f64) -> MultiPolygon { + let main = polygon![ + (x: 0.0, y:0.0), + (x: ring_size , y:0.0), + (x: ring_size , y:ring_size ), + (x: 0.0, y:ring_size ), + ] + .translate_center() + .rotate(30.) + .translate(0., radius); + + let center_point = Point(Coordinate { x: 0., y: 0. }); + let parts = rng.gen_range(20..120); + let rotation = 360. / parts as f64; + let direction = if rng.gen_bool(0.5) { -1. } else { 1. }; + let fragment = main.difference( + &main.rotate_around_point(direction * rotation, center_point), + 100., + ); + let mut polygons: MultiPolygon = MultiPolygon(Vec::new()); + for index in 0..parts { + polygons.merge(&fragment.rotate_around_point(rotation * index as f64, center_point)); + } + polygons +}