xxxxxxxxxx
var inc = 0.01;
var start = 0;
var c1, c2;
var stars = [];
var maxStars = 15;
function setup() {
createCanvas(900,400);
// Colors
c1 = color(random(80,110), random(200,250), 255);
c2 = color(random(10), random(50,100), random(180,210));
b1 = color(0);
b2 = color(random(30,60), random(50,70), random(100,170));
s1 = random(190,215);
s2 = random(30,60);
// Fill star array
for (var i = 0; i < maxStars; i++) {
if (stars.length < maxStars) {
stars.push(new Star(random(50, windowWidth - 50), random(40,200)));
} else if (stars.length >= 10) {
stars.length = 0;
stars.push(new Star(random(50, windowWidth - 50), random(40,200)));
}
}
}
function draw() {
// background(34, 0, 73);
gradient(0,0, windowWidth, windowHeight,b1, b2);
// Stars
for (var i = 0; i < stars.length; i++) {
stars[i].display();
}
// Sun
noStroke();
fill(s1, s2, 0);
ellipse(250,80,70,70);
// Lake
gradient(0,330, windowWidth, 70, c1, c2);
stroke(255);
noFill();
beginShape();
var xoff = start;
for (var x = 0; x < width; x++) {
stroke(255);
var y = noise(xoff) * height;
vertex(x,y);
xoff += inc;
}
endShape();
start += inc;
}
function gradient(x,y,w,h,c1,c2) {
noFill();
for (var i = y; i<=y+h; i++) {
var inter = map(i,y,y+h, 0,1);
var c = lerpColor(c1, c2, inter);
stroke(c);
line(x,i,x+w,i)
}
}
// Generate new background and lake gradient on click
function mousePressed() {
setup();
}
function Star(x,y) {
this.x = x;
this.y = y;
this.display = function() {
noStroke();
ellipseMode(CENTER);
fill(27, 78, 114);
ellipse(x,y,15,15);
fill(229, 255, 196);
ellipse(x,y,5,5);
}
}