Hi Processing World!
I'm still a newbie here, and never have coded something substantial in my life. I'm wondering if I can get some help in figuring out how to make my lines move independently from each other and go off of different angles, instead of just bouncing back off the screen in the same direction. Either I need to have them rotate as they hit the side of the screen, or I need point X to follow point Y. Not sure what my solution would be but I hope someone here can help.
Thank you,
Clinton
Bouncer a; Bouncer []c= new Bouncer [150]; import processing.sound.*; AudioIn in; Amplitude amp; void setup(){
size( 1500,1500); for (int i=0; i<c.length;i++){ c[i] = new Bouncer(random(-8,8), random (-8,8), random(255)); }
}
void draw(){
background(0,.000005);
for (int i=0; i<c.length;i++){ c[i].display(); c[i].bounce(); }
}
class Bouncer {
float r, g, b, s, xpos, ypos, xpos2, ypos2, xspeed, yspeed; Bouncer(float tempxspeed, float tempyspeed, float tempr) {
xspeed = tempxspeed;
yspeed = tempyspeed;
xpos = width/2;
ypos = height/2;
xpos2 = width/4;
ypos2 = height/4;
r = tempr;
g = random(255);
b = 255;
s = 5;
}
void display() {
stroke(255);
fill(255);
line(xpos, ypos, xpos2, ypos2);
}
void bounce() {
if ( xpos > width - s/2 || xpos < s/2 ) {
xspeed = xspeed * -1;
}
if ( ypos > height - s/2 || ypos < s/2 ) {
yspeed = yspeed * -1;
}
if ( xpos2 > width - s/2 || xpos2 < s/2 ) {
xspeed = xspeed * -1;
}
if ( ypos2 > height - s/2 || ypos2 < s/2 ) {
yspeed = yspeed * -1;
}
xpos = xpos + xspeed;
ypos = ypos + yspeed;
xpos2 = xpos2 + xspeed;
ypos2 = ypos2 + yspeed;
} }