xxxxxxxxxx
let numMountains = 5;
let mountainSpeeds = [];
let mountainHeights = [];
let mountainColors = [];
function setup() {
createCanvas(400, 400);
noLoop();
for (let i = 0; i < numMountains; i++) {
mountainSpeeds.push(random(0.005, 0.03));
mountainHeights.push(random(height / 3, height * 2 / 3));
mountainColors.push(color(0));
}
}
function draw() {
background(255);
for (let i = 0; i < numMountains; i++) {
drawMountain(i);
}
}
function drawMountain(index) {
stroke(mountainColors[index]);
fill(mountainColors[index]);
beginShape();
let xOffset = 0;
for (let x = 0; x < width; x += 10) {
let yOffset = noise(xOffset) * 100;
vertex(x, height - mountainHeights[index] - yOffset);
xOffset += mountainSpeeds[index];
}
vertex(width, height);
vertex(0, height);
endShape(CLOSE);
}