RC Day 3

Not that much to talk about today.

In the morning, I had a minor epiphany about wasm importing this morning after some sleep. rust-wasm-template makes an npm package, and create-wasm-app can import it directly as JS, whereas rust-wepback-template makes a wasm bundle that your js has to import like wasm. *I think*, and I’m not sure yet, that’s why I’m trying both.

I created an event tomorrow afternoon to meet Rust interested people.

In the morning I went through the tutorial for the Rust+WASM book, which uses the (simpler) wasm-pack template.

Funnily enough, the tutorial goes through writing Conway’s Game of Life, which is what I paired on with Malte yesterday. It’s nice to get a second take on the task, and to see it done in clean, tutorial-level idiomatic Rust.

I got the game of life to show on my localhost:8080, and it’s really fast!

In the first half of the tutorial we display the board as text in html: On the Rust side we print the board as a string of squares, and on the JS side we use requestAnimationFrame to display the string as the content of a <pre> tag.

It’s really fast! It runs at max 60fps, (because that’s my display’s resolution, and requestAnimationFrame) and min 45 fps. The tiny lags are because of the browser having to do layout work, but the function runs in 1.5 ms on average.

The rest of the tutorial shows how to do it with canvas, ie, having javascript read the raw memory of the board to display it with canvas, which is really cool.

First time I used a raw pointer in Rust! The board exposes itself as a pointer, and then the JS side can read the memory into uint8s and draw the canvas accordingly.

I think I’ll be able to use this tomorrow for paint by numbers. We’ll load the image into a canvas, and have Rust do canvas.context.getimagedata() and pull out the data itself.

Or, possibly, have Rust implement the web worker function itself. I think I’m going to try to get here early tomorrow (9am lol) and spend time by myself in the morning finishing the Rust Wasm Book tutorial and trying to move the paint by numbers web worker into wasm.

I paired with Emily this afternoon and I showed her Advent of Code Day 18, which looks really hard to me, and she convinced me we’re going to go solve it tomorrow!

comments powered by Disqus