Skip to main content

Terrain Generation in Processing

I have finally gotten deeper into programming with Processing and recently watched a video on terrain generation by Daniel Shiffman (The Coding Train) on 3D Terrain Generation with Perlin Noise in Processing .

Daniel is an excellent teacher and provides complete source code for all his presentations.

This is a little recorded sample of my attempt to implement it and add some Minecraft-like coloring.

Here is my Processing code, based heavily on Daniel’s.

// Terrain Generation and Flyby using Processing
// Douglas E. Welch After Daniel Schiffman -

int cols, rows;
int scl = 20;
int w = 2200;
int h = 2200;

float flying=0;

float [][] terrain;

void setup() {
size(1280, 720, P3D);

cols = w /scl;
rows = h/scl;

terrain= new float[cols][rows];

void draw() {

flying += - .1;

float yoff = flying;

for (int y = 0; y< rows; y++) {
float xoff=0;
for (int x=0; x < cols; x++) {
terrain[x][y] = map(noise(xoff, yoff), 0, 1, -150, 150);
yoff +=0.1;


translate(width/2, height/2);

translate(-w/2, -h/2);

for (int y = 0; y< rows-1; y++) {
for (int x=0; x < cols; x++) {

//rect(x*scl, y*scl, scl, scl);
vertex(x*scl, y*scl, terrain[x][y]);
vertex(x*scl, (y+1)*scl, terrain[x][y+1]);

// Water
if (terrain[x][y] <= -60) {
fill(0, 0, 150);
if (terrain[x][y] >= -59 && terrain[x][y] <=0) {
fill(0, 100, 0);

if (terrain[x][y] >= 0 && terrain[x][y] <=50) {

// Snow
if (terrain[x][y] > 50) {
fill(255, 255, 255);



Popular posts from this blog

Audio: Social Networks - LIVE from the Library Internet Seminar - November 8, 2007

This night we talked about social networks, the Writer's Guild Strike, traditional media and the future of new media. Listen to this seminar Links discussed in this seminar: MySpace - Add me as a friend in MySpace Facebook - Add me as a friend on Facebook LinkedIn - Connect to me on LinkedIn YouTube - Watch my videos on YouTube Garden Fork TV The Minimalist with Mark Bittman quarterlife The Wish Book Holiday Podcast Project

This DIY domino clock tells the time using three LED-lit tiles via Arduino Blog

After coming across Carbon Design Group’s Domino Wall Clock, which uses electronic magnetic coil motors to reveal white dots, Instructables member “Kothe” decided to create a simplified version of their own. The clock is comprised of three custom dominoes — the first tile for hours, the second and third for minutes. Unlike its inspiration, Kothe’s device uses addressable RGB LEDs as dots that allow for a variety of colors to shine through. Read This DIY domino clock tells the time using three LED-lit tiles via Arduino Blog An interesting link found among my daily reading

Onion Pi makes your web traffic anonymous via Open Electronics

Hmmm, might be an easy (and relatively cheap) way to play around with Tor and learn a bit more about this anonymizing service. -- Douglas Adafruit’s Onion Pi is a Tor proxy that makes your web traffic anonymous, allowing you to use the internet free of snoopers and any kind of surveillance. Follow Adafruit’s tutorial on setting up Onion Pi and you’re on your way to a peaceful anonymous browsing experience. Tor is an onion routing service – every internet packet goes through 3 layers of relays before going to your destination. This makes it much harder for the server you are accessing (or anyone snooping on your Internet use) to figure out who you are and where you are coming from. Read Onion Pi makes your web traffic anonymous via Open Electronics * A portion of each sale from directly supports our blogs ** Many of these books may be available from your local library. Check it out! An interesting link found among my daily reading