xxxxxxxxxx
61
// Daniel Shiffman
// http://codingtra.in
// https://youtu.be/IKB1hWWedMk
// https://thecodingtrain.com/CodingChallenges/011-perlinnoiseterrain.html
// Edited by SacrificeProductions
var cols, rows;
var scl = 10;
var w = 1000;
var h = 1000;
var flying = 0;
var terrain = [];
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
cols = w / scl;
rows = h / scl;
colorMode(HSB, 360, 100, 100, 100);
fill(random(100, 200), 70, 100, 20);
for (var x = 0; x < cols; x++) {
terrain[x] = [];
for (var y = 0; y < rows; y++) {
terrain[x][y] = 0; //specify a default value for now
}
}
}
function draw() {
flying -= 0.005;
var yoff = flying;
for (var y = 0; y < rows; y++) {
var xoff = 0;
for (var x = 0; x < cols; x++) {
terrain[x][y] = map(noise(xoff, yoff), 0, 1, -100, 100);
xoff += 0.02;
}
yoff += 0.5;
}
background(50);
translate(0, -200);
rotateX(PI / 3);
noStroke();
if (frameCount%10==0){
fill(random(100, 200), 70, 100, 20);
}
translate(-w / 2, -h / 2);
for (var y = 0; y < rows - 1; y++) {
beginShape(TRIANGLE_STRIP);
for (var x = 0; x < cols; x++) {
vertex(x * scl, y * scl, terrain[x][y]);
vertex(x * scl, (y + 1) * scl, terrain[x][y + 1]);
}
endShape();
}
}