xxxxxxxxxx
275
let fishes = [];
let bubbles = [];
let movingY = 400;
let mainfishX = 0;
let pointLeft = true; //for mainFish
let switchOn = false; //for light
let tank;
//ROOM COLOR
//SWITCH DIMENTIONS
let switchX = 50,
switchY = 100,
switchW = 15,
switchH = 30;
//the room is dark before you turn on the light
let roomCol = 0,
switchCol = ("PapayaWhip ")
function setup() {
createCanvas(600, 400);
//tank
tank= new FishTank(100,150,400,200);
//bubbles loop
for (let i = 0; i < 10; i++) {
let x;
let y;
let r;
bubbles[i] = new Bubble(x, y, r);
}
//fishes loop- algorithm
for (let f = 0; f < 4; f++) {
let x = 250 + 3 * f;
let y = 250;
fishes[f] = new Fish(x, y, 20, 45);
}
}
function draw() {
background(roomCol);
//table
fill(201, 191, 155);
noStroke();
rect(0, 330, 600, 70);
//check if switch is pressed
if (switchOn) {
roomCol = "PapayaWhip";
switchCol = 0;
} else {
roomCol = 0;
switchCol = (255);
}
fill(switchCol);
rect(switchX, switchY, switchW, switchH);
//volcano bubbles
volbubble(130, movingY + 30);
volbubble(135, movingY + 5);
volbubble(131, movingY);
//volcano move
if (movingY > 160) {
movingY = movingY - 1;
}
if (movingY <= 160) {
movingY = 300;
}
//fish algorithm
for (let f = 0; f < fishes.length; f++) {
fishes[f].move();
fishes[f].show();
}
//MAP MOUSEX VALUE FROM WINDOW WIDTH TO TANK WIDTH
mainfishX = map(mouseX, 0, 600, 125, 460);
if (mouseX < pmouseX) {
mainfishLeft(mainfishX, 250);
pointLeft = true;
}
if (mouseX > pmouseX) {
mainfishRight(mainfishX, 250);
pointLeft = false;
}
if (mouseX === pmouseX) {
if (pointLeft === true) {
mainfishLeft(mainfishX, 250);
}
if (pointLeft === false) {
mainfishRight(mainfishX, 250);
}
}
//tank
tank.tankBg();
tank.volcano();
tank.tankglass();
tank.tanktop();
//bubbles
for (var i = 0; i < height; i++) {}
for (let i = 0; i < bubbles.length; i++) {
bubbles[i].move();
bubbles[i].show();
if (bubbles[i].fill <= 0) {
bubbles.splice(i, 1);
}
}
}
////FiSH////
class Fish {
constructor(x, y, r) {
this.x = x;
this.y = y;
this.r = r;
}
move() {
this.x = this.x + random(-3, 3);
this.y = this.y + random(-3, 3);
}
show() {
fill(8, 59, 12);
ellipse(this.x + 29, this.y, 20, 25);
fill(35, 150, 44);
ellipse(this.x, this.y, 40, 30);
fill("white");
ellipse(this.x - 10, this.y - 5, 10);
fill("grey");
ellipse(this.x - 13, this.y - 5, 4);
fill(62, 66, 63, 90);
ellipse(this.x + 10, this.y + 85, 60, 10);
}
}
//MAIN FISH
function mainfishLeft(x, y) {
//tail
fill(128, 0, 0);
ellipse(x + 29, y, 20, 25);
//body
fill(255, 0, 0);
ellipse(x, y, 50, 30);
//eyes
fill("white");
ellipse(x - 10, y - 5, 10);
//pupil
fill("black");
ellipse(x - 13, y - 5, 4);
//shadow
fill(62, 66, 63, 90);
ellipse(x + 10, y + 85, 60, 10);
}
function mainfishRight(x, y) {
//tail
fill(128, 0, 0);
ellipse(x - 29, y, 20, 25);
//body
fill(255, 0, 0);
ellipse(x, y, 50, 30);
//eyes
fill("white");
ellipse(x + 10, y - 5, 10);
//pupil
fill("grey");
ellipse(x + 13, y - 5, 4);
//shadow
fill(62, 66, 63, 90);
ellipse(x - 10, y + 85, 60, 10);
}
//TANK
class FishTank{
constructor(x,y,w,h){
this.x=x;
this.y=y;
this.w=w;
this.h=h;
}
tankglass(){
stroke("white");
strokeWeight(3);
fill(153, 255, 255, 90);
rect(this.x, this.y, this.w, this.h);
}
tanktop(){
fill("grey");
noStroke();
rect(this.x - 5, this.y, 410, 15);
rect(this.x - 5, this.y + 200, 410, 10);
fill("black");
rect(this.x - 10, this.y, 420, 10);
}
tankBg(){
fill(122, 63, 11);
rect(this.x, this.y + 175, 400, 25);
}
volcano(){
fill(82, 74, 24);
quad(this.x + 10, this.y + 180, this.x + 60, this.y + 180, this.x + 45, this.y + 150, this.x + 25, this.y + 150);
}
// clicked(){
// let d=dist(mouseX.mouseY,this.x,this.y);
// if (d >this.x && d < this.x + this.w && d > this.y && d < this.y + this.h){
// var r = random(10, 30);
// var b = new Bubble(mouseX, mouseY, r, 0, -1);
// bubbles.push(b);
// }
// }
}
//VOLCANO BUBBLES//
function volbubble(x, y) {
// stroke(255);
// strokeWeight(2);
noStroke();
fill(99, 132, 224, 80);
ellipse(x, y, 15);
}
//BUBBLES//
class Bubble {
constructor(x, y, r) {
this.x = x;
this.y = y;
this.r = r;
this.fill = random(220, 255);
this.fade = 255;
}
move() {
this.x = this.x + random(-5.5, 5.5);
this.y = this.y + random(-5.5, 5.5);
}
show() {
noStroke();
fill(this.fill, this.fade);
ellipse(this.x, this.y, this.r, this.r);
this.fill = this.fill - 0.4;
this.fade = this.fade - 0.7;
}
}
function mouseDragged() {
let r = random(10, 30);
let b = new Bubble(mouseX, mouseY, r, 0, -1);
bubbles.push(b);
}
// array of bubbles when mouse pressed
function mousePressed() {
var r = random(10, 30);
var b = new Bubble(mouseX, mouseY, r, 0, -1);
bubbles.push(b);
//switch light
if (mouseX >= switchX && mouseX <= switchX + switchW && mouseY >= switchY && mouseY <= switchY + switchH) {
switchOn = !switchOn;
}
}