# Chaos Game The [Chaos Game](https://en.wikipedia.org/wiki/Chaos_game) (wikipedia) is a fractal generator. This program works by iteratively walking half way between the current location (initially the center of the sprite but could be random) and a randomly selected vertex. Each time a step is made, a pixel is filled in at the destination. The color is based on the vertex's color. Right now, this program uses a hard-coded triangle and so generates a [Sierpinsky triangle](https://en.wikipedia.org/wiki/Sierpi%C5%84ski_triangle). Other shapes can be used -- see the Chaos Game Wikipedia link for examples. I have not provided a UI for altering these shapes at run time. ## Building ### For desktop Run `cargo run --release`, just like any other binary crate. Use `cargo run --features=dynamic_linking` for faster cycle times when modifying the code. This feature is a pass-through to Bevy's dynamic linking feature. ### For WASM Run `cargo run --release --target=wasm32-unknown-unknown`. This will start a dummy webserver, *wasm-server-runner*, which in turn hosts a dummy webpage that loads the WASM file. Run the program by visiting the dummy site in your browser: [http://localhost:1334] To make a "real" deployment, I use the output of `wasm-bindgen --web` and the tiny index.html here in the repo. These are thrown at whatever webserver is available at hand. ```sh # Build the program user@host:~/chaos-game-rs$ cargo build --release --target wasm32-unknown-unknown user@host:~/chaos-game-rs$ wasm-bindgen --no-typescript --target web --out-dir out/ --out-name "chaos-game-rs" target/wasm32-unknown-unknown/release/chaos-game-rs.wasm # Place the HTML, JS, and WASM all together in a web root. # Here, I'll reuse the ./out/ folder user@host:~/chaos-game-rs$ cp index.html ./out/index.html # Host the files with an HTTP server. Any will do, but some are easier to # configure than others. # BusyBox's httpd (note that "httpd" might mean Apache2 or Nginx on your # machine. Check the manual for the right flags). user@host:~/chaos-game-rs$ httpd -f -p 8080 -h ./out # Python's http.server module user@host:~/chaos-game-rs$ python3 -m http.server -p 8080 -d ./out # Or, again, the wasm-sever-runner, from the start of this section user@host:~/chaos-game-rs$ cargo run --target=wasm32... # etc, etc ``` The `wasm-bindgen` tool offers [other module formats](https://rustwasm.github.io/docs/wasm-bindgen/reference/deployment.html), which may be of interest for anyone trying to use this as one of many pages on a site. I may come back to explore that later, but for now it's just a couple of files to manually move around.