We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, i'm new to processing. Below is the code for 1 bouncing ball. But I would like to add another ball. How do i edit my codes?
int rad = 60;
float xpos, ypos;
float xspeed = 2.8;
float yspeed = 2.2;
int xdirection = 1;
int ydirection = 1;
void setup()
{
size(640, 360);
noStroke();
frameRate(30);
ellipseMode(RADIUS);
xpos = width/2;
ypos = height/2;
}
void draw()
{
background(102);
xpos = xpos + ( xspeed * xdirection );
ypos = ypos + ( yspeed * ydirection );
if (xpos > width-rad || xpos < rad) {
xdirection *= -1;
}
if (ypos > height-rad || ypos < rad) {
ydirection *= -1;
}
ellipse(xpos, ypos, rad, rad);
}
Answers
I guess same advices in the post below apply to you: %%-
http://forum.processing.org/two/discussion/902/duplicating-animated-parts
Also, after posting a code here, highlight it and hit CTRL+K to format it! *-:)