xxxxxxxxxx
54
let x = 0;
let y1;
let mountains = [];
function setup() {
createCanvas(windowWidth, windowHeight);
mountains.push(generateMountains(300));
mountains.push(generateMountains(200));
mountains.push(generateMountains(100));
}
function generateMountains(h){
let yOff1 = random(1000000);
let x = 0;
let mountain = [];
while(x <= width){
e = 1 * noise(1 * h/400 * yOff1) + 1 * noise(2 * h/400 * yOff1) + 0.5 * noise(4 * h/400 * yOff1);
y1 = pow(e, h/100 * 0.2);
//y1 = pow(noise(yOff1),3);
mountain.push(createVector(x,-y1*h));
x+=1;
yOff1+=0.002;
}
return mountain;
}
function drawMountains(mountain){
push();
translate(0,height);
let clr = 255;
for(let mountain of mountains){
stroke(clr);
fill(clr);
beginShape();
vertex(0,0);
for(let m of mountain){
vertex(m.x,m.y)
}
vertex(width,0);
endShape();
clr -= 50;
}
pop();
}
function draw() {
background(0);
drawMountains(mountains);
}