#wave #collapse #function #rust

billow

Simple Wave Function Collapse implementation in Rust

2 unstable releases

1.0.0 Sep 2, 2022
0.2.0 Sep 2, 2022
0.1.0 Sep 2, 2022

#968 in Game dev

35 downloads per month

GPL-3.0 license

2MB
446 lines

Billow

Crates.io Billow documentation

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.

Usage

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.

Dependencies

~13–28MB
~239K SLoC