Last active
April 9, 2017 18:41
-
-
Save jkwok91/2c6556f307cfd8b56e6163461e0b191f to your computer and use it in GitHub Desktop.
flap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// based on dan shiffman's coding challenge #11 | |
// draw terrain as triangle_strips | |
// then manipulate vertices of the triangle_strips | |
var points; | |
var cols, rows; | |
var unit; | |
var minZ, maxZ; | |
var flying; | |
function setup() { | |
createCanvas(800, 600, WEBGL); | |
unit = 15; | |
cols = 25; | |
rows = 25; | |
//stroke(255); | |
minZ = -150; | |
maxZ = 150; | |
flying = 0; | |
} | |
function calculatePts() { | |
points = []; | |
var yoff = flying; | |
for (var j = 0; j <= rows; j++) { | |
var row = [] | |
var xoff = 0; | |
for (var i = 0; i <= cols; i++) { | |
var z = map(noise(xoff, yoff), 0, 1, minZ, maxZ); | |
row.push(z); | |
xoff += 0.1; | |
} | |
points.push(row); | |
yoff += 0.1; | |
} | |
} | |
function draw() { | |
background(0); | |
calculatePts(); | |
push(); | |
rotateX(-0.5); | |
translate(-(cols*unit)/2, -(rows*unit)/2, 0); | |
for (var j = 0; j < rows; j++) { | |
beginShape(TRIANGLE_STRIP); | |
for (var i = 0; i < cols; i++) { | |
var z = points[j][i]; | |
var red = map(z, minZ, maxZ, 0, 255); | |
var green = map(j*10, 0, rows*10, 0, 255); | |
fill(red, green, 200); | |
vertex(i*unit, j*unit, points[j][i]); | |
vertex(i*unit, (j+1)*unit, points[j+1][i]); | |
} | |
endShape(); | |
} | |
pop(); | |
flying -= 0.25; | |
} |
Author
jkwok91
commented
Apr 9, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment