xxxxxxxxxx
129
var movementY;
function setup() {
createCanvas(400, 400);
}
/* bubbles
function bubble(x,y) {
fill(92, 209, 203, 80);
ellipse(x, y, 15);
}
bubble(140, movementY + 20);
bubble(145, movementY + 10);
bubble(150, movementY + 40);
if (movementY > 1) {
movementY = movementY - 1
}
else {
movementY = 150;
}
*/
function Bubble(x, y) {
this.x = x;
this.y = y;
this.lifespan = 255;
this.col = color(255, 100, 76, 80);
this.diameter = 23;
this.display = function() {
stroke(255);
fill(255, this.lifespan);
ellipse(this.x, this.y, this.diameter, this.diameter);
};
this.update = function() {
this.x = this.x + random(-1, 1);
this.y = this.y + random(-1, 1);
this.lifespan--;
if(this.lifespan < 0){
//this.();
}
};
this.isFinished = function() {
if(this.lifespan < 0 ){
return true;
} else {
return false;
}
};
this.isTouching = function() {
if(this.x > width || this.x < 0){
return true;
} else if(this.y > height || this.y < 0){
return true;
} else {
return false;
}
}
}
var bubbles = [];
function setup() {
createCanvas(600, 400);
}
function mousePressed() {
var b = new Bubble(mouseX, mouseY);
bubbles.push(b);
}
function draw() {
let x1 = width/2;
let y1 = height/2;
let x2 = 300;
let y2 = 300;
let d = int(dist(x1, y1, x2, y2));
push();
translate((x1 + x2) / 2, (y1 + y2) / 2);
rotate(atan2(y2 - y1, x2 - x1));
text(nfc(d, 1), 0, -5);
pop();
background(100, 180, 190);
noStroke();
fill(255, 248, 110);
ellipse(width/2, height/2, 300, 300);
if(mouseX > d & mouseY > d) {
for(var i = bubbles.length-1; i >= 0; i--){
bubbles[i].update();
bubbles[i].display();
if(bubbles[i].isFinished() || bubbles[i].isTouching()){
bubbles.splice(i, 1);
}
}
}
else{
}
}
/*
print("HELP");
}
else {
print("FACK");
}
*/