Thinking and practise, Coding.

Aim of todays session was to create a bouncing ball.

Image

Then the challenge was to create numerous balls. This is the code I used, numerous balls effectively appeared but then disappeared again so only one ball was visible.

float xpos;
float ypos;
float xinc;
float yinc;

int numb=10;
float [] xposar;
float[] yposar;
float[] xincar;
float [] yincar;

void setup(){
size(800,600);
xposar=new float[numb];
yposar=new float[numb];
xincar=new float[numb];
yincar=new float [numb];

xpos=random(800);
ypos=random(600);
xinc=random(-15,15);
yinc=random(-15,15);

for(int lop=0;lop<numb;lop=lop+1){
xposar[lop]=random(800);
yposar[lop]=random(600);
xincar[lop]=random(-15,15);
yincar[lop]=random(-15,15);
}

smooth();

}

void draw(){
background(255);
fill(100,100,100,80);
ellipse(xpos,ypos,10,10);

xpos=xpos+xinc;
ypos=ypos+yinc;

if(xpos>800) xinc=xinc*-1;
if(xpos<0) xinc=xinc*-1;
if(ypos>600) yinc=yinc*-1;
if(ypos<0) yinc=yinc*-1;
//now plot multiple balls

for(int lop=0;lop<numb;lop=lop+1){
ellipse(xposar[lop],yposar[lop],10,10);
xposar[lop]=xposar[lop]+xincar[lop];
yposar[lop]=yposar[lop]+yincar[lop];

}
}

Then I made the balls stay and changed the amount from 10 to 1000. It looked like this…

Image

 

Then to connect all the balls together using code if(lop<numb-1)line(xposar[lop],yposar[lop],xposar[lop+1],yposar[lop+1]); Screen Shot 2013-11-06 at 15.13.39

 

 

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

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