Hi,
I am trying to figure out toxiclibs VerletPhysics2D
and AttractionBehavior2D
.
What I want to achieve is that use the attractor so the small particles will be attracted to the big center circle but do not go inside the shape and move around the boundary of the big circle. Here is an image I captured from Box2D example (I want to create the same behavior using toxiclibs):
And here is what I have so far using toxiclibs:
import toxi.geom.*;
import toxi.physics2d.*;
import toxi.physics2d.behaviors.*;
VerletPhysics2D physics;
Vec2D center;
void setup() {
size(500, 500);
physics = new VerletPhysics2D();
physics.setDrag(0.05f);
physics.setWorldBounds(new Rect(0, 0, width, height));
for (int i = 0; i < 100; i++) {
VerletParticle2D p = new VerletParticle2D(new Vec2D(random(width), random(height)));
physics.addParticle(p);
physics.addBehavior( new AttractionBehavior2D(p, 20, -1, 0.01) );
}
center = new Vec2D(width/2, height/2);
AttractionBehavior2D ab = new AttractionBehavior2D(center, 200, 1, 0.01);
physics.addBehavior( ab );
}
void draw() {
background(200);
physics.update();
ellipse(center.x, center.y, 100, 100);
for (VerletParticle2D p : physics.particles) {
ellipse(p.x, p.y, 10, 10);
}
}
Here is the screenshot. I would like the small particles to be around the boundary of the big circle:
Thank you for any help and guidance!