Generating Terrain with JavaScript and Canvas
I had such great plans for today, but then I came across Paul Boxley's blog post "Terrain generation with the diamond square algorithm". You owe it to yourself to check his post out, since he explains the concepts better, presents the results better, and totally did it first.
Since the post combined JavaScript, isometric graphics and procedural content (three of my go-to favorite things!), I found myself with an itch in need of scratching. I came up with the following after a few hours of hacking around:
(see this demo on its own page)
you'll need a canvas-capable browser that supports getImageData() to see anything cool above. sorry.
I'm using my own implementation of the diamond-square algorithm. My version is recursive and theoretically works with a heightmap of arbitrary dimensions, although it's pretty inefficient. Things I'd like to add to this implementation are z-ordering (it always draws the polys in the same order, to occasional ill effect), and a real shading algorithm.
All in all, it's a pretty satisfying proof-of-concept, and I'm excited to have more code to contribute to my upcoming canvas library (which I will post about any day now...)