differential_growth/lib.rs
1//! [![github]](https://github.com/driescruyskens/differential-growth-rust) [![crates-io]](https://crates.io/crates/differential-growth) [![docs-rs]](https://docs.rs/differential-growth)
2//!
3//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
4//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
5//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs
6//!
7//! # Overview
8//!
9//! 
10//!
11//! This crate provides a very easy to use Differential Growth algorithm as well as an example sketch using the excellent [nannou](https://crates.io/crates/nannou) crate.
12//! It's as simple as providing a Vec of starting points, calling [`DifferentialGrowth::tick()`] to advance one iteration of the algorithm and obtaining the new state
13//! using [`DifferentialGrowth::get_points()`].
14//!
15//! Get up and running quickly by using an included point generator function like [`generate_points_on_circle()`] to generate your starting points.
16//!
17//! Having a basic knowledge of the differential growth algorithm is highly recommended:
18//! - <https://inconvergent.net/generative/differential-line/>
19//! - <https://inconvergent.net/2016/shepherding-random-growth/>
20//!
21//! # Example
22//!
23//! The best way to understand this crate is by taking a look at `/example` folder. You can run it on any platform running `cargo run --example example`.
24//!
25//! Otherwise, below is a quick reference on how to use this crate.
26//!
27//! ```rust
28//! # use differential_growth::{generate_points_on_circle, DifferentialGrowth};
29//! # use nalgebra::Point2;
30//! # use nannou::{event::Update, prelude::*, window, App, Frame};
31
32//! // Generate a set of starting points.
33//! // You do not have to use the included helper function,
34//! // you could for example pass points drawn by the mouse.
35//! let starting_points: Vec<Point2<f64>> = generate_points_on_circle(0.0, 0.0, 10.0, 10);
36//!
37//! // Instantiate DifferentialGrowth.
38//! // the choice of input parameters is very import to the
39//! // succesful working of the algorithm. A value to big or too small
40//! // or a wrong combination of values can make the algorithm behave
41//! // like it doesn't work.
42//! // Here I've provided values that I tested and like.
43//! let mut dg = DifferentialGrowth::new(starting_points, 1.5, 1.0, 14.0, 1.1, 5.0);
44//!
45//! // Advance the algorithm 1 iteration.
46//! dg.tick();
47//!
48//! // Get the newly calculated points.
49//! let points_to_draw: Vec<Point2<f64>> = dg.get_points();
50//!
51//! // draw the result by
52//! // - drawing a line between consecutive Vec elements.
53//! // - drawing a line between the first and the last element.
54//! ```
55//!
56
57mod differential_growth;
58mod node;
59#[cfg(feature = "point_generators")]
60mod point_generators;
61
62pub use crate::differential_growth::*;
63#[cfg(feature = "point_generators")]
64pub use crate::point_generators::*;