xxxxxxxxxx
110
let bubbles = [];
let cones = [];
class Cone {
constructor(_x,_y,_z,_h,_d){
this.x = _x;
this.y = _y;
this.z = _z;
this.h = _h;
this.d = _d;
this.color = color(random(255),random(255),random(255));
}
display() {
push();
// noStroke();
translate(this.x,this.y,this.z);
fill(this.color)
rotateY(frameCount * 0.01);
// rotateX(frameCount * 0.01);
cone(this.h,this.d)
pop();
}
move() {
this.y = (this.y+10)%width*random(1);
}
}
class Bubble{
constructor(_x,_y,_z,_sz){
this.x = _x;
this.y = _y;
this.z = _z;
this.sz = _sz;
this.color = color(100,200,0)
}
display() {
push();
noStroke();
translate(this.x,this.y,this.z);
fill(this.color)
sphere(this.sz);
pop();
}
move(){
this.x += random(-5,5);
this.y += random(-5,5);
this.z += random(-5,5);
}
intersect(other) {
let d = dist(this.x,this.y,this.z,other.x,other.y,other.z);
if (d < (this.sz+other.sz)) {
return true;
} else {
return false;
}
}
}
function setup() {
createCanvas(800, 800,WEBGL);
b1 = new Bubble(0,0,10,40);
cam = createCamera();
for (let i = 0; i < 10; i ++) {
cones.push(new Cone(random(width),random(height),10,50,50))
}
c = new Cone(0,0,10,50,50);
}
function draw() {
background(220);
c.display();
for (let c1 of cones) {
c1.display();
c1.move()
}
// for (let b of bubbles){
// let intersected = false;
// if (b.intersect(b1) ==true) {
// intersected = true;
// } else {
// intersected = false;
// }
// if (intersected == true) {
// b.color = color(0,0,100);
// } else {
// b.color = color(0,100,0);
// }
// b.move();
// b.display();
// }
cam.lookAt(c.x,c.y,c.z);
// b1.display();
// b1.z = cos(frameCount*0.1)*100;
}