Rust implementation of the wave function collapse algorithm. Based on Oskar Stålberg's and Martin Donald detailed explanation.
🚧 This is a work in progress.
This is a general purpose library, I provide implementations for the image::DynamicImage
and bevy::prelude::Image
types.
use billow::Wave;
use image::DynamicImage;
fn main() {
let input: Vec<DynamicImage> = load_assets("assets/basic");
let (width, height) = (20usize, 20usize);
// New wave with a 20x20 grid
let mut wave = Wave::new(input, width, height);
// Populate the grid and choose a random starting point
wave.initialize()
// Run the algorithm.
// This will try to collapse the grid to a single state.
// `100` is the number of iterations.
// each iteration will collapse one cell and try to propagate the changes.
wave.collapse(100).expect("Failed to collapse");
}
See examples for more.