xxxxxxxxxx
88
//noise wave code from https://p5js.org/examples/math-noise-wave.html
let yoff = 0;
let star1x, star1y, star2x, star2y;
let star1Fade, star2Fade;
let fadeRate;
star1Fade = -5;
star2Fade = -5;
fadeRate = 20;
function setup() {
createCanvas(600, 400);
}
function draw() {
background(29, 41, 81);
randomSeed();
mountain();
stars();
river();
reflection();
}
function reflection(){
fill(0, 119, 190);
beginShape();
let xoff = 0;
for (let x = 0; x <= width; x += 10) {
let y = map(noise(xoff, yoff), 0, 1, 300, 400);
vertex(x, y);
xoff += 0.05;
}
yoff += 0.01;
vertex(width, height);
vertex(0, height);
endShape(CLOSE);
}
//mountains and water shape
function mountain(){
noStroke();
//MOUNTAIN CENTER
c = color(61, 41, 28);
fill(c);
triangle(350, 220, 600, 370, 130, 370);
//MOUNTAIN LEFT
c = color(81, 47, 25);
fill(c);
triangle(150, 215, 500, 400, -150, 400);
//MOUNTAIN RIGHT
c = color(102, 52, 20);
fill(c);
triangle(600, 200, 930, 400, 300, 400);
}
//blinking stars
function stars() {
if(star1Fade < 0){
//create a new star with a new fade
star1x = random(width);
star1y = random(height*0.5);
star1Fade = 255;
}
if(star2Fade < 0){
//create a new star with a new fade
star2x = random(width);
star2y = random(height*0.5);
star2Fade = 255 - random(5,20);
}
push();
fill(255, star1Fade);
ellipse(star1x, star1y, 4);
fill(255, star2Fade);
ellipse(star2x, star2y, 8);
star1Fade -= fadeRate;
star2Fade -= fadeRate;
pop();
}
//river
function river(){
fill(0, 119, 190);
noStroke();
rect(0, 400, 400, 100);
}