This is a experiment and learning project for rendering Mandelbrot and Julia sets using Rust and displaying them in a web browser via WASM.
Features:
- Interactively explore the fractal via the mouse with pan and zooming
- Mandelbrot and Julia sets
- A range of colour pallettes to pick from
- Configurable options such as image size, colour scaling, inner set colour.
- Export images as PNG
A couple of supporting projects are used, WASM-Pack and wasm-bindgen
One principal was to keep the Rust code loosely coupled, and free from any dependencies on the WASM/hosting layer, which in this case is JavaScript. So although wasm-bindgen is used, there is no use of js-sys or web-sys, the exported Rust code exposes just simple arrays of basic types (e.g. integers and floats).
The web layer is pure JavaScript & HTML, and requires no bundling, WebPack or transpiling.
See the examples folder for more
- Rust & Cargo (see https://www.rust-lang.org/tools/install)
- Make
- Something that can act as a local HTTP server, e.g. https://www.npmjs.com/package/http-server or https://github.com/m3ng9i/ran
- Node - Only if planning to run bundling & deployment
- Run
make build
- Start HTTP server in root of repo
- Open
/web
path on local server address e.g. http://localhost:8080/web/
To deploy the app, ESBuild is used to combine the HTML and JS in the web folder with the WASM and JS in the pkg folder, and create an output bundle.
Simply run make deploy
.
See build.mjs file for more details