xxxxxxxxxx
65
let cube = [];
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
for (let i = 0; i < 100; i++) {
//spacing the bubbles out
let x = random(width);
let y = random(height);
let r = random(5, 30);
cube[i] = new Cube(x, y, r);
// r is radious of the bubble
}
}
function draw() {
background(0);
lights();
push();
translate(-width/2,-height/2);
for (let i = 0; i < cube.length; i++) {
cube[i].move();
cube[i].show();
}
pop();
}
// Bubble Object, generic template
class Cube {
// Data, constructor
constructor(x1, y1, r1) {
this.x = x1;
this.y = y1;
this.r = r1;
}
// Functionality
move() {
// this.x = this.x + random(-5, 5);
// this.y = this.y + random(-5, 5);
}
show() {
noStroke();
fill(255, 100);
rotateX(frameCount * 0.0005);
rotateY(frameCount * 0.0005);
push();
fill(255);
translate(this.x, this.y);
box(this.r);
pop();
}
}