topical media & game development
graphic-processing-algorithm-Ch06-p147-p147.pde / pde
int nsprings = 4;
MySpring [] s = new MySpring[nsprings];
void setup() {
size(200, 200);
for(int i=0; i<nsprings; i++){
s[i] = new MySpring();
s[i].xpos = random(width);
s[i].ypos = random(height);
s[i].Rx = s[i].xpos;
s[i].Ry = s[i].ypos;
}
}
void draw() {
background(200);
for(int i=0; i<nsprings; i++){
if(s[i].released)s[i].move();
ellipse(s[i].xpos, s[i].ypos , 10,10);
}
for(int i=0; i<nsprings-1; i++)
line(s[i].xpos, s[i].ypos ,s[i+1].xpos, s[i+1].ypos);
}
void mouseDragged() {
for(int i=0; i<nsprings; i++)
if(dist(mouseX,mouseY,s[i].xpos,s[i].ypos)<10){
s[i].released = false;
s[i].xpos = mouseX;
s[i].ypos = mouseY;
}
}
void mouseReleased(){
for(int i=0; i<nsprings; i++)
s[i].released = true;
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.