void display() {
if(newBall) {
// make ball grow
}
else {
// make ball drop
}
}
class Bubble {
color c;
//velocity and accelerator
float v, ac;
//initial position
float x0, y0;
// dimension
float di, d;
Bubble(float tempX, float tempY){
c = color(255);
v = 0;
ac = 0.1;
x0 = tempX;
y0 = tempY;
di = 1;
}
void display(){
fill(c);
noStroke();
ellipseMode(CENTER);
if (di <= 80 && mousePressed){
ellipse(x0, y0, di, di);
di++;
}else if (di== 80 || mousePressed == false){
frozen[j] = di;
}
}
void drop(float tempD){
d = tempD;
ellipse(x0, y0, d, d);
y0 = constrain(y0, 0, height - d/2);
y0 = y0+v;
v += ac;
if (y0 >= height-d/2){
v*=-0.9;
}
}
}
Bubble [] myBubble = new Bubble[0];
//frozen count number
int j = -1;
//frozen count array
float [] frozen = new float[100];
//initial position
float xpos, ypos;
void setup(){
size (300,600);
smooth();
j = constrain (j, -1, 99);
}
void draw(){
background(50);
//display balls
if(myBubble.length >0){
for (int i=0; i<myBubble.length; i++){
myBubble[i].display();
myBubble[i].drop(frozen[i]);
}
}
}
void mousePressed(){
xpos = mouseX;
ypos = mouseY;
//new object
Bubble b = new Bubble(xpos, ypos);
//append array
myBubble = (Bubble[]) append(myBubble, b);
}
void mouseReleased(){
j++;
}
Click on the Canvas to drop the "Ping Pong". The longer you hold your mouse key, the bigger the Ping Pong is.
This is my Lesson 4 Project, after learning the concept of object, class and array. I struggled for long hours to get the "display()" function right, but no luck. I wanted the Ping Pong to keep the size after being generated by the mousePress(), and not to be affected by the next mousePress(). But instead the "display()" showing a flicker every time when the mouse is pressed.
I found myself lacking of the programing process. I can't get the logic right before I sketch. All my lin