Add missing documentation
CI / cargo fmt (push) Failing after 25s
CI / cargo test (GPU) (push) Has been cancelled
CI / cargo test (push) Has been cancelled

This commit is contained in:
2026-06-27 11:02:19 -04:00
parent a9da463041
commit 344ecc3450
4 changed files with 46 additions and 8 deletions
+19
View File
@@ -1,3 +1,17 @@
//! # Chaos Game
//!
//! Fractal flames are a class of
//! [iterated function systems](https://en.wikipedia.org/wiki/Iterated_function_system)
//! that generate images following a simple algorithm:
//!
//! - Pick a starting point `(x, y)`
//! - Iterate:
//! - Pick a [`Transform`] from the set of available transforms
//! - Apply the current point to the chosen transform, generating a new point `(x, y)`
//! - Plot the new point `(x, y)`
//!
//! This algorithm is also known as the ["chaos game"](https://en.wikipedia.org/wiki/Chaos_game),
//! and it forms the basic system for producing images.
use crate::transform::Transform;
use glam::{Vec2, vec2};
use rand::distr::{Distribution, StandardUniform};
@@ -42,6 +56,10 @@ pub fn step_chaos_game<R: Rng>(
)
}
/// Iterator for chaos game state. Holds the current point and references to all other data
/// necessary to generate fractal flame images.
///
/// New points in the chaos game are produced by iterating on the chaos game.
pub struct ChaosGame<'a, R: Rng> {
current_point: Vec2,
rng: &'a mut R,
@@ -50,6 +68,7 @@ pub struct ChaosGame<'a, R: Rng> {
}
impl<'a, R: Rng> ChaosGame<'a, R> {
/// Create a new chaos game iterator
pub fn new(rng: &'a mut R, transforms: &'a [Transform], weights: &'a [f32]) -> Self {
let current_point = vec2(rng.sample(BiUnit), rng.sample(BiUnit));
ChaosGame {