DiamondSquare
DiamondSquare copied to clipboard
Implementation of the diamond-square algorithm in JS.
DiamondSquare
It's like... autogenerated heightmaps for your projects, man.
Example
var myInitMap = [ 4,1,2,4,
1,4,2,2,
3,2,1,6,
2,1,1,5 ];
// Create a new DiamondSquare algorithm from the initial map, with a random
// roughness factor
var ds = new DiamondSquare(myInitMap,4,4,Math.random()*10);
// Iterate until you're satisfied. The map doubles in size with each
// iteration.
ds.iterate();
...
ds.iterate();
// Then the data you want is in:
ds.dataStore;
There's a demonstration file that just renders the heightmap to canvas (with some rather buggy bilinear interpolation) but the intention is that you use it for geometry or something exciting like that!