Hello, everyone!
I am trying to adapt Mr. Shiffman's Simple Spring Example*
to store all my Vec2D's inside an ArrayList.
*
http://www.shiffman.net/itp/classes/nature/toxiclibs_2010/simplespring/As easy as pie… I guess.
However, my particles don´t stop when they reach the ground
like they should.
When I print my particle position, everything works fine until
it reaches thes maximum height. Here is a print…
{x:250.0, y:413.63782}{x:250.0, y:433.8689}{x:250.0, y:455.92014}{x:250.0, y:479.8978}{x:250.0, y:500.0}{x:250.0, y:303.57776}{x:250.0, y:103.50757}{x:250.0, y:0.0}{x:250.0, y:500.0}{x:250.0, y:0.0}{x:250.0, y:500.0}{x:250.0, y:NaN}{x:250.0, y:NaN}{x:250.0, y:NaN}{x:250.0, y:NaN}NaN… so, I've found a way to transform a number into something else…nice…Nobel worthy…
Here's my code…
import toxi.physics2d.*;import toxi.physics2d.behaviors.*;import toxi.geom.*;ArrayList allNodes;VerletPhysics2D physics;void setup(){ frameRate(30); size(500,500); smooth(); background(255); allNodes = new ArrayList(); allNodes.add(new Particle(width/2,height/2)); physics=new VerletPhysics2D(); physics.addBehavior(new GravityBehavior(new Vec2D(0,0.001))); Vec2D center = new Vec2D(width/2,height/2); Vec2D extent = new Vec2D(width/2,height/2); physics.setWorldBounds(Rect.fromCenterExtent(center,extent));}void draw(){ physics.update(); background(255); for(int i=0; i<=allNodes.size()-1;i++){ Particle thisParticle = (Particle)allNodes.get(i); physics.addParticle(thisParticle); thisParticle.display(); if(mousePressed){ if(dist(mouseX,mouseY,thisParticle.x,thisParticle.y)<=30){ thisParticle.lock(); thisParticle.x= mouseX; thisParticle.y= mouseY; thisParticle.unlock(); } } } if(keyPressed) { if (key == '+' || key == '+') { allNodes.add(new Particle(random(width),random(height))); println("# NODES | "+allNodes.size()); } }}class Particle extends VerletParticle2D { Particle(float x, float y) { super(x,y); } void display() { fill(255,100,100,100); noStroke(); ellipse(x,y,30,30); }}Any help with this witchcraft dilemma would be much appreciated…
Thnaks for your time!