First of all: I'm a complete Processing-Newby, I mean a REAL newby learning everything about programming for the first time and just via Internet so there a many things I don't understand or didn't get yet.
Therefore I'm not making any games or realy usefull programs but just small stuff to help me learn and understand the processing language (so please don't wonder how anyone can have as "small" problems, I realy need some help)
and I'm German so chances are that I say something gramatically wrong or misspell words.
But now to something completly different: My problem.
I want to write a sketch in which an amount of balls (7+) bounce through the picture and change direction as wel as color(randomly) everytime they hit the "border".
The single balls shall move with different speeds and "bounce" at different spots.
int radius = 30;
float xpos,ypos;
float xspeed=random(1,10);
float yspeed=random(1,10);
int xdirection = 1;
int ydirection = 1;
float r=random (255);
float b=random (255);
float g=random (255);
void setup ()
{
size (800,800);
noStroke ();
frameRate(30);
smooth();
xpos = 0;
ypos = 800-radius;
}
void draw ()
{
background (0);
fill (r,g,b);
xpos=xpos+(xspeed*xdirection);
ypos=ypos-(yspeed*ydirection);
if (ypos<0+radius||ypos>800-radius) {
ydirection*=-1;
r=random (255);
b=random (255);
g=random (255);
}
if(xpos>800-radius||xpos<0) {
xdirection*=-1;
r=random (255);
b=random (255);
g=random (255);
}
ellipse(xpos, ypos,radius,radius);
}
this is my sketch so far,
if I increase the number of balls, they change direction as soon as the first "hits" the "side-border"
thats perfectly logical to me but what do I have to do to make every ball jump individually?
I tried a ball class but since all about Processing is realy new to me, I couldn't get a class that actually worked, I don't know what part of the comands to write in the class and which to write in other parts of the code and where there (void draw, or outside of all voids, or should I build a void move/void display)?
I hope someone can help me and thanks for that