Idea
I really like experimenting with random functions and math relations and then displaying them. So I want to make this website where you can write a script to run on every pixel and then display the result. Originally this was just rust code creating ppm pictures, but a web app is more accessible.
Implementation
I am still not the biggest JS fan and more comfortable with rust, so I will use WASM to make rust run in the browser. This also has some performance benefits and I can easily add scripting languages
Canvas
The first step was to have something I can draw pixels to with JS. I went with a canvas and drawing filled rects to it.
WASM
Rust to WASM seems to have a very mature pipeline and its very easy. You just write normal rust code and all functions, types, etc you want to expose to JS you can use #[wasm_bindgen] from the wasm-bindgen crate. Then after installing wasm-pack you can run wasm-pack build --target web to compile the rust to wasm. It also automatically generates the JS glue and TS headers. In JS you just have to import a init function and the exposed wasm functions you want to use. The browser does the rest!
Everything will run locally in the browser, which also means we can use githubs free static hosting
, which I already setup with a github action, check it out here! Currently I have only got a bare minimum UI and no language support. Next on my list is adding Rhai support (scripting language similar to rust) and getting that to actually output some pixels.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.