We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › dividing Traer springs into separate lists
Page Index Toggle Pages: 1
dividing Traer springs into separate lists (Read 443 times)
dividing Traer springs into separate lists
Apr 12th, 2009, 2:49pm
 
I want to be able to draw springs within my Traer physics system but without drawing all of them - as it stands I have to cycle through the whole list. Is there a way to each spring an index, or place it in a arraylist which I could then use isolated from the global list of springs? I made a parent class called Link which spawns a spring but I am not sure how I you can add a spring to an arraylist...any ideas?

thanks!
Re: dividing Traer springs into separate lists
Reply #1 - Apr 15th, 2009, 8:22am
 
Somewhere in your code, you are create springs with the makeSpring command. All you need to do is to add the resulting Spring to your ArrayList or Vector:

Code:

// create physics
ParticleSystem physics = new ParticleSystem(5.0, 0.05);

// create ArrayList
ArrayList allSprings = new ArrayList();

// create particles and spring
p1 = physics.makeParticle(mass1, x1, y1, z1);
p2 = physics.makeParticle(mass2, x2, y2, z2);
Spring mySpring = physics.makeSpring(p1, p2, stren, damp, len);

// add Spring to ArrayList
allSprings.add(mySpring);
Page Index Toggle Pages: 1