xxxxxxxxxx
let number_of_bubbles = 1193;
let bubbles;
let movedist = 1;
let bubble_size = 1;
let blacks = 100;
let keepOn = true;
function setup() {
background(0);
createCanvas(windowWidth, windowHeight);
bubbles = [];
//bubbles[0] = new Bubble(200, 200, 40);
//bubbles[1] = new Bubble(400, 200, 20);
for (let i = 0; i < number_of_bubbles; i++){
bubbles[i] = new Bubble(random(0,width),
random(0,height),
i);
}
}
function draw() {
//background(222,222,222,2);
if (keepOn) {
for (let i =0; i < number_of_bubbles; i++){
bubbles[i].move();
bubbles[i].show();
}
}
}
function mouseClicked(){
background(0);
if (keepOn){
keepOn = false;
} else {
keepOn = true;
}
}
function keyPressed() {
if (keyCode === UP_ARROW) {
bubble_size += 1;
} else if (keyCode === DOWN_ARROW) {
bubble_size -= 1;
} else if (keyCode === LEFT_ARROW) {
movedist -= 1;
} else if (keyCode === RIGHT_ARROW) {
movedist += 1;
} else if (keyCode === CONTROL) {
blacks -= 1;
}
return false; // prevent default
}
class Bubble{
constructor(x, y, index){
this.x = x;
this.y = y;
this.index = index;
this.radius = bubble_size;
this.color = random(111,205);
this.speed = movedist;
this.angle = noise(this.x+this.y/1234);
if(index % 115 != 0){
this.r = map(random(),0,1,0,255);
this.g = map(random(),0,1,0,255);
this.b = map(random(),0,1,0,255);
} else {
this.r = map(random(),0,1,0,0);
this.g = map(random(),0,1,0,0);
this.b = map(random(),0,1,0,0);
this.radius = bubble_size * 4;
this.speed = movedist*4;
}
}
move(){
this.angle = this.angle + 0.5 - noise(this.y/100);
this.angle = this.angle + 0.5 - noise(this.x/500);
this.x = this.x + sin(this.angle)*movedist;
this.y = this.y + cos(this.angle)*movedist;
if (this.x < 0){
this.x = width;
}
if (this.x > width){
this.x = 0;
}
if (this.y < 0){
this.y = height;
}
if (this.y > height){
this.y = 0;
}
}
show(){
if(this.index % blacks == 0){
this.r = map(random(),0,1,0,0);
this.g = map(random(),0,1,0,0);
this.b = map(random(),0,1,0,0);
this.radius = bubble_size * 4;
this.speed = movedist*4;
}
//stroke(this.color, 44);
noStroke();
fill(this.r, this.g, this.b);
ellipse(this.x, this.y, bubble_size);
}
}