Fractal terrain generation in 130 lines of Javascript


#1

[Permalink]


#2

http://madebyevan.com/webgl-water/


#3

That's certainly more elegant than this one:

http://www.atarimagazines.com/compute/issue87/Fractal_Mountains_For_Amiga.php

195 lines of Amiga BASIC.

It's kinda fun to duplicate those BASIC demos in JavaScript and Canvas, and every bit as interesting (imho) to see the differences in coding styles.


#4

How about mountains including sun, clouds, fog and snow in 500 lines of text:-
https://www.shadertoy.com/view/4slGD4

Needs a WebGL enabled browser.


#5

Fun!

The terrain is somewhat unbelievable, though. After the generation, I'd suggest running some simulated erosion on it. A few iterations of simulated water flow and material removal. Assumption of homogenous soil will do the job; asking for simulated harder rock intrusions would be too much.


#6

Yeah, I think that's the largest problem with any of the various random terrain generators, they're missing the next step (likely because it's a very complicated step and likely extremely hard to code for FOSS) of errosion simulation. This would also allow you to know where rivers and lakes would be, and thus make it a lot easier to use these sorts of terrain for more in-depth creative works like fiction and gaming.


#7

Maybe I'm being naive here, but couldn't you model erosion fairly easily using some kind of sandpile model? I don't know about javascript, but you could easily do that in under 20 lines of python.


#8

A ways back I was messing with the original simcity source and as part of figuring out how it all worked, re-made the map generation code in javascript:

http://xzzy.org/projects/sc/

It's delightfully simple once you figure out what it's doing.. each feature (lakes, rivers, forests) have a 2D array defined that functions like a stamp. For rivers, the generator picks a random x,y coordinate, stamps into the terrain, then moves the x,y in a random direction and stamps again. It repeats until it hits the edge of the map.

Lakes and forests run on a similar concept, but the loop is modified so it behaves differently.


#9

Reticulating splines.


#10

that water simulation is pretty amazing, thanks for sharing!

I was especially impressed once i realized i could lift the sphere out of the water and smash it back down, or have it partially submerged.

the only real flaw i've noticed is that water can't overcome the surface tension and separate, like when you smash the sphere downwards you'd expect some water to become airborn. likely that bit adds a lot of complication to the simulation.


#11

After looking at a few of these terrains, I was thinking that I'd want to pick a good one and 3D print it for table top gaming. smile


#12

POV-Ray can produce much the same thing with a script of about 130 characters.


#13

This topic was automatically closed after 5 days. New replies are no longer allowed.