Midterm Project
I changed my idea from killing brain cells to spry bugs.
Brain model can't show sphere when I put them together, even though I use brain.disablestyle(); still not work.
when we click the mouse, it will spray bugs, make them change color.
///////////coding///////////////////////////////////////
Ball[] balls = new Ball[20];
//PShape brain;
PShape spray;
float angle;
void setup(){
size(600,600,P3D);
background(0);
for (int i = 0; i < balls.length; i ++){
balls[i]= new Ball(random(width/2)-10,random(height/2),random(-10,0));
}
spray = loadShape("spray.obj");
}
void draw(){
lights();
//rotateX(radians(angle));
background(0);
angle+=1;
pushMatrix();///////spray
//rotateX(radians(mouseX));
//rotateY(radians(mouseY));
translate(mouseX,mouseY);
scale(2);
shape(spray,0, 0,10,10);
popMatrix(); /////// spray mouse
pushMatrix(); /////box that hold the brain cells begin
noFill();
stroke(255,241,113,150);
strokeWeight(3);
translate(width/2,height/2);///let box in center
rotateX(radians(angle));
box(width/3, height/3, 200);
//box(200,200,200);
//println(mouseX);
popMatrix(); //// box that hold the brain cells end
pushMatrix();
translate(185,195);
for (int i = 0; i < balls.length; i ++){
balls[i].update();
balls[i].display();
}
popMatrix();
println(mouseY);
// saveFrame("output/gol_####.png");
}
///////box class////////////////////////////////////////////////////////////////////////////////////////////////
class Ball {
float x,y,z; ///location
int dx=1; ///direction for x
int dy =1;
int dz= 1;
float sx= .1; // speed for x
float sy=.1;
float sz=.001;
int r = 20;//////radius for sphere
int depth;
PShape bug;
Ball(float tx,float ty,float tz){
bug = loadShape("bug.obj");
x = tx;
y= ty;
z= tz;
bug.disableStyle();
}
void update(){
x += dx* sx; /// the function to make it move bounce back and forth.location = speed * direction
y += dy*sy;
z += dz*sz;
if( x> (200-r)){ //change direction for sphere in x axis.
sx=random(3,5);
dx=-1;
}
if(x <(0+r)){
sx=random(1,3);
dx=1;
} ///change direction for sphere in x axis
if(y > (200-r)){///change direction for sphere in y axis
sy= random(1,2);
dy=-1;
}
if(y <(0+r)){
sy= random(1,3);
dy =1;
} ////change direction for sphere in y axis
if(z>(200-r)){ ///change direction for sphere in z axis
sz=random(1,2);
dz=-1;
}
if(z<(0+r)){
sz=random(-1,1);
dz=1;
} // change direction for sphere in z axis
}
void display(){
///scale(7);
// shape(bug,0,0,10,10);
if (mousePressed){
pushMatrix();
translate(x, y,z); ////make brain cells in center of the box
lights();
noStroke();
fill(255,246,240);
//stroke(255,100);
//strokeWeight(3);
shape(bug, 0,0, 10,10);
//sphere(r);
popMatrix();
}else{
pushMatrix();
translate(x, y,z); ////make brain cells in center of the box
lights();
noStroke();
fill(160,71,8);
//stroke(255,100);
//strokeWeight(3);
shape(bug, 0,0, 10,10);
//sphere(r);
popMatrix();
}
}
}
Comments
Post a Comment