My older kid loves mazes…that combined with the fact that I haven’t written code just for fun in far too long resulted in this: a maze generator in Go, compiled to WebAssembly, that generates printable mazes.
If you like mazes, there’s an excellent resource: Mazes for Programmers - Usually this is a book I choose to gift to friends of mine who can write code.
That book is wonderful.
At the chance of having missed it, is the source code available somewhere?
Getting it cleaned up and on GitHub will be next weekend’s project. :)
I actually miss the time when many websites looked like this. It was a good indicator nthat the site was there because of its content. Not because of the looks.
It does what it need to do. Visual design is secondary.
For my thesis, I programmed Ariadne, a tool for teaching (maze) algorithms to students. It allows you to generate and maze and then visually program an algorithm that tries to find a path to a given target.
If you want to give it a try, click on “Generate a maze” on the left. Then choose the menu item “Algorithm” > “Load Simple Ariadne Thread Algorithm” and press the “Play” button in the top right.
If you want the pages to be printable, I’d recommend adding a
@media printrule to hide the generator box.
Interested to hear more about the garbage collector story when compiling Go to WASM. How does that work?
Tangential, but when you compile Go to webassembly, does it compile the garbage collector with it?
I asked myself the same question and I used the wabt toolkit and its excellent
wasm2ctool to decompile OP’s maze generator. Yes, it does seem to embed Go’s GC:
It seems to take just over a second to generate/render a 200x200 maze for me.
I’d love to know where the bottlenecks are – I’m v. interested in Go/Wasm.
The lion’s share of the time is spent encoding the image to PNG to export from WASMland to JSland. I added an option to turn off PNG compression, that speeds things up considerably.
I think if I sent a display list to JSland and had it draw on a canvas, it would be faster but I wrote this first for the command line and just had it save images.
Me too, Golang compiled WebAssembly isn’t inherently slow.
You might be interested in this roguelike game written in Golang that has been compiled for wasm and is playable in the browser here https://harmonist.tuxfamily.org/play/index.html