We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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;
} }
Answers
each line has two ends. You use xspeed and yspeed for BOTH. I changed that by using xspeed2 and yspeed2 for the 2nd end now.
Hey thanks for this! Quick question... I'm trying to do a sound experiment and I'd like to figure out how to manipulate the lines via sound. My idea is that each time the input is triggered, all of the lines will be shot to the edges of the screen... Like gravity took over the lines and are holding them close to the edge when the sound is hit.
Let me know if this makes sense and if it's possible! Thanks.
Sure it’s possible
Just look at examples of library minim and look at beat detection or some analysis tools for sound
Thanks for this, I'm going to try work on a few things now. You guys are awesome!
for minim:
http://code.compartmental.net/tools/minim/quickstart/