sketch-asu
var Man;
var grass = 0.4;
var grassSpeed = 0.07;
var mountainFront = 0.008;
var mountainFrontSpeed = 0.0005;
var mountainBack = 0.01;
var mountainBackSpeed = 0.0002;
var bubbles = [];
function setup() {
createCanvas(480, 480);
frameRate(20);
for (var i = 0; i < 9; i++){
var bubblesX = random(width);
var bubblesY = random(0, 200);
bubbles[i] = makebubbles(bubblesY, bubblesX);
}
}
function draw(){
background(221,191,218);
Sun();
MountainBack();
MountainFront();
Grass();
image(Man,mouseX,300,80,80);
updatebubbles();
addbubbles();
}
function Sun(){
noStroke();
fill(250,70,22,120);
ellipse(350, 200, mouseX+500);
fill(250,70,22,40);
ellipse(350, 200, mouseX+350);
fill(250,70,22,100);
ellipse(350, 200, mouseX+200);
}
function preload(){
Man = loadImage("https://i.imgur.com/9AUtJm7.png");
}
function MountainBack(){
noStroke();
fill(0,109,87);
beginShape();
for (var i = 0; i < width; i ++){
var x = (i * mountainBack) + (millis() * mountainBackSpeed);
var y = map(noise(x), 0, 1.5, 50, 300);
vertex(i, y);
}
vertex(width, height);
vertex(0, height);
endShape();
}
function MountainFront(){
noStroke();
fill(208,240,192);
beginShape();
for (var i = 0; i < width; i ++){
var x = (i * mountainFront) + (millis() * mountainFrontSpeed);
var y = map(noise(x), 0, 1.2, 150, 250);
vertex(i, y);
}
vertex(width, height);
vertex(0, height);
endShape();
}
function Grass(){
noStroke();
fill(156,176,113);
beginShape();
for (var i = 0; i < width; i ++){
var x = (i * grass) + (millis() * grassSpeed);
var y = map(noise(x), 0, 1.1, 350, 370);
vertex(i, y);
}
vertex(width, height);
vertex(0, height);
endShape();
}
function makebubbles(bubblesX, bubblesY){
var bubbles = {
x: bubblesX,
y: bubblesY,
velocity: random(3, 8),
size: random(5, 15),
move: movebubbles,
show: showbubbles,
}
return bubbles;
}
function movebubbles(){
this.x -= this.velocity;
this.y -= this.velocity / random(5, 20);
}
function showbubbles(){
strokeWeight(1);
stroke('LightBlue');
fill(101,208,255,80);
circle(this.x, this.y, this.size);
curve(this.x + this.size, this.y, this.size, this.size/2);
}
function updatebubbles(){
for(i = 0; i < bubbles.length; i++){
bubbles[i].move();
bubbles[i].show();
}
}
function addbubbles(){
if (random(0,2) < 0.5){
var bubblesX = width;
var bubblesY = random(0, height/2);
bubbles.push(makebubbles(bubblesX, bubblesY));
}
}