Bouncing ball code and break down sort of.

Ok so the bouncing ball. I wanted to do something a little different so I found a really cheap motion blur effect from http://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/ it had some pretty cool tips for processing on of which was replacing the background() call with a rect() call that is the size of the screen and has transparency to it so every frame the layers build up and hide the previous circles. It is quick, dirty and inefficient in the long run but it works nicely for a short project like this. Now for the code

int CIRCLE_SIZE = 20;
float postion_x;
float postion_y;
float delta_x = random(-5, 5);
float delta_y = random(-5, 5);

void setup(){
size(500, 500);
noStroke();
smooth();

postion_x = width / 2;
postion_y = height / 2;

if(delta_x < 1 && delta_x > -1){
delta_x = 1;
}
if(delta_y < 1 && delta_y > -1){
delta_y = 1;
}
}

void update(){
if(postion_x < 0 + CIRCLE_SIZE/2){
delta_x = random(1, 5);
}
else if(postion_x > width – CIRCLE_SIZE/2){
delta_x = random(-5, -1);
}

if(postion_y < 0 + CIRCLE_SIZE/2){
delta_y = random(1, 5);
}
else if(postion_y > height – CIRCLE_SIZE/2){
delta_y = random(-5, -1);
}

postion_x += delta_x;
postion_y += delta_y;
}

void draw(){
update();//updates things like movement and postion

//Hacky way to get cheap motion blur replaces background() call
fill(0, 50);
rect(0, 0, width, height);

//circle with color based on mouseX and mouseY
fill(255, map(mouseX, 0, width, 1, 255), map(mouseY, 0, height, 1, 255));
ellipse(postion_x, postion_y, CIRCLE_SIZE, CIRCLE_SIZE);

}

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s