#generative-art #growth #differential #generative #art #algorithm #points

differential-growth

A Rust implementation of the differential growth algorithm

4 releases (2 breaking)

0.3.1 Jul 5, 2023
0.3.0 Aug 1, 2022
0.2.0 Jul 31, 2022
0.1.0 Jul 31, 2022

#6 in #generative-art

MIT/Apache

360KB
236 lines

Differential Growth Rust

example1

Overview

This crate provides a very easy to use Differential Growth algorithm as well as an example sketch using the excellent nannou crate. 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 using [DifferentialGrowth::get_points()].

Get up and running quickly by using an included point generator function like [generate_points_on_circle()] to generate your starting points.

Having a basic knowledge of the differential growth algorithm is highly recommended:

Example

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.

Otherwise, below is a quick reference on how to use this crate.

# use differential_growth::{generate_points_on_circle, DifferentialGrowth};
# use nalgebra::Point2; 
# use nannou::{event::Update, prelude::*, window, App, Frame};

// Generate a set of starting points.
// You do not have to use the included helper function,
// you could for example pass points drawn by the mouse.
let starting_points: Vec<Point2<f64>> = generate_points_on_circle(0.0, 0.0, 10.0, 10);
// Instantiate DifferentialGrowth.
// the choice of input parameters is very import to the
// succesful working of the algorithm. A value to big or too small
// or a wrong combination of values can make the algorithm behave
// like it doesn't work.
// Here I've provided values that I tested and like.
let mut dg = DifferentialGrowth::new(starting_points, 1.5, 1.0, 14.0, 1.1, 5.0);

// Advance the algorithm 1 iteration.
dg.tick();

// Get the newly calculated points.
let points_to_draw: Vec<Point2<f64>> = dg.get_points();

// draw the result by
// - drawing a line between consecutive Vec elements.
// - drawing a line between the first and the last element.

References

Dependencies

~3MB
~61K SLoC