final pic

Bouncing Balls/Coins

Here is a link to my project!

http://www.openprocessing.org/sketch/374140

Beginning Of My Project

For my final project I wasn’t in the mood to make a game, so I wanted to make something cool. That’s why I decided to make this interactive bouncing ball visual. When you start it, it begins with having ten different color balls all bouncing around the walls.

ArrayList<Circle> circles;
Circle c;
float xPos=200;
int xDir=1;
Circle d;
Circle e;
color col;

void setup()
{
size (900, 900);
background(100);
frameRate(40);
fill(0, 255, 0);
circles = new ArrayList<Circle>();
int count = 0;
while (count < 10) {
Circle c = new Circle( random(width), 90, random(1, 20), 30, 90, false);
circles.add(c);
count = count +1;
}
}

Interactive Part

After awhile they will stop bouncing, but it takes a pretty long time. If you click on the screen it will add more balls, which are a shade of green or yellow. I decided to add this part to my project because I wanted the person viewing my project to be able to do something themselves.

void mousePressed() {
circles.add(new Circle(mouseX, mouseY, 3, 30, 700, true));
}

Problems I Had

I had a terrible time trying to get the collision to work. Doing collision in processing isn’t very fun to begin with, and making it so it had to check every ball was even worse. That was the biggest problem I encountered while working on this project, but once I figured it all out, I felt great! I also made it look like the objects bouncing around are spinning in air by accident because I made it so the width of the ball would be normal at the bottom of the page, and then as it went up it went smaller and smaller until it looked like it was spinning.

while (count < circles.size()) {
Circle c = circles.get(count);
c.updatePosition();
c.display();
count = count +1;
int num = count+1;
while (num < circles.size()) {
if ( count != num) {
Circle d = circles.get(num);
if (dist(c.x, c.y, d.x, d.y)<circles.size()) {
c.yvel = -1 * c.yvel;
}
if ( count != num) {
Circle e = circles.get(num);
if (dist(c.x, c.y, e.x, e.y)<circles.size()) {
c.xvel = -1 * c.xvel;
}
}
num = num +1;
}
}
 void updatePosition() {
 yvel = yvel + 1;
 y = y + yvel;
 if (y >height) {
 y = height;
 yvel = -1*yvel;
 }
x = x +xvel;
if (x > width) {
x = height;
xvel = -1*xvel;
}
if (x < 0) {
xvel = -1*xvel;
x=0;
}
}

My Experiences With This Project

I had a lot of fun making this project. I really enjoyed seeing everything come to life and I like the way everything bounces around the screen. For some reason this is the only idea I could come up with for my final project and I’m glad I could make it work.

Leave a Reply

Your email address will not be published. Required fields are marked *