Skip to content

Instantly share code, notes, and snippets.

@ianfitzpatrick
Last active January 23, 2018 05:33
Show Gist options
  • Save ianfitzpatrick/6b5394f3e512e14dd6a55d162793a50d to your computer and use it in GitHub Desktop.
Save ianfitzpatrick/6b5394f3e512e14dd6a55d162793a50d to your computer and use it in GitHub Desktop.
Perlin Terrain Map from Nature of Code book ported to python mode for processing
w = 1400
h = 1000
scl = 20
flying = 0
terrain = []
def setup():
global terrain, rows, cols
size(600, 600, P3D)
cols = w / scl
rows = h / scl
terrain = [[0] * rows for col in range(cols)]
fill(102, 204, 255, 80)
def draw():
global flying, terrain, rows, cols
flying -= 0.3
yoff = flying
for y in range(rows):
xoff = 0
for x in range(cols):
terrain[x][y] = map(noise(xoff, yoff), 0, 1, -100, 150)
xoff += 0.2
yoff += 0.2
translate(0, 400)
background(0)
noStroke()
rotateX(PI/3);
translate(-w / 3, -h /3 );
for y in range(rows - 1):
beginShape(TRIANGLE_STRIP)
for x in range(cols):
vertex(x*scl, y*scl, terrain[x][y])
vertex(x*scl, (y+1)*scl, terrain[x][y+1])
endShape()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment