xxxxxxxxxx
88
// Set up some constants and variables
const points = 800,
inc = 0.005,
stars = 500;
let start = 100,
rotangle = 0,
rotangleShift = 0,
starsx = [],
starsy = [];
// Setup functiom
function setup() {
createCanvas(windowWidth, windowHeight);
noStroke();
rotangleShift = PI / 5000;
// Fill up the stars array
for (let i = 0; i < stars; i++) {
starsx.push(random(-width, width));
starsy.push(random(-height, height));
}
}
// Draw function
function draw() {
let xoff = start
background("#04072C");
rotate(rotangle)
// Plot the stars
push()
stroke(255, 125)
for (let i = 0; i < stars; i++) {
if (i % 4 == 0) {
strokeWeight(random(1, 4))
}
point(starsx[i], starsy[i])
}
pop()
// Make an array of y-points to work through
y1Array = [];
// Fill the array
for (let i = 0; i < points; i++) {
y1Array.push(noise(xoff) * height * 0.85);
xoff += inc;
}
// Draw the top shape
push()
noStroke()
rotate(-rotangle)
fill("#572819")
beginShape()
vertex(width, height)
for (let i = points; i > 0; i--) {
let x = i * (width / points);
let y = y1Array[i] - (height / 12)
vertex(x, y);
}
vertex(0, height)
endShape(CLOSE)
pop()
// Draw the bottom shape
push()
rotate(-rotangle)
fill("#A75942")
beginShape();
vertex(0, height)
for (let i = 0; i < points; i++) {
let x = i * (width / points);
let y = y1Array[floor(i / 3)] + (height / 3)
vertex(x, y);
}
vertex(width, height);
endShape(CLOSE);
pop()
// Increment the mountains passing and the stars rotating
start += inc;
rotangle += rotangleShift;
}