Awhile ago, I wanted to play around with web-centric computing using webassembly and rust. For a project, I picked out the hash-life algorithm, an super-fast algorithm for simulating Conway’s Game of life.
The app looks like this (click to go to deployed demo):
To test the full power of the hashlife algorithm, I would recommend:
- “Select builtin pattern” and selecting either “twinprimes.rle”
- Pressing both “fast-forward” button and the “skip” button a few times
- Increasing the brightness to the max
- Waiting for a few seconds.
You should see the results look something like this:
Note that the dots coming out of the machine correspond one to one with the twin primes! This works because the machine acts like a prime sieve, eliminating all non-primes, and then also eliminating unpaired primes.
Key learnings
- The toolchain for developing wasm and js bindings from rust is pretty mature. I was able to do everything without any trouble.
- It is easiest to start out without build tooling, and add that it later if you need to plug it into a larger project.
- Remember that webassembly doesn’t have great support for garbage collection. Programming in rust helps with this.
- It is fun to implement an algorithm like this without frameworks