problem with particles
in
Contributed Library Questions
•
6 months ago
If you look at the image and take the 2nd particle from the left top corner. Then i would expect it to go down since there is a lot more with attraction.
Is it the library or am i doing something wrong?
- import traer.physics.*;
- ParticleSystem physics;
- float particleMass = 1.0;
- void setup() {
- size(600, 600);
- smooth();
- frameRate(30);
- physics = new ParticleSystem();
- physics.setGravity(0.0);
- physics.setDrag(1.0);
- }
- void draw() {
- background(255);
- physics.tick();
- for(int i = 0; i < physics.numberOfSprings(); i++) {
- Spring s = physics.getSpring(i);
- Particle anchor = s.getOneEnd();
- Particle node = s.getTheOtherEnd();
- noStroke();
- fill(255, 0, 0, 100);
- ellipse(node.position().x(), node.position().y(), 15, 15);
- stroke(0);
- line(node.position().x(), node.position().y(), anchor.position().x(), anchor.position().y());
- }
- }
- void mousePressed() {
- Particle anchor = physics.makeParticle(particleMass, mouseX, mouseY, 0);
- anchor.makeFixed();
- Particle node = physics.makeParticle(particleMass, mouseX, mouseY, 0);
- // If they are strong they act like a stick. If they are weak they take a long time to return to their rest length
- float strength = 0.1;
- // If springs have high damping they don't overshoot and they settle down quickly, with low damping springs oscillate.
- float damping = 1;
- // the spring wants to be at this length and acts on the particles to push or pull them exactly this far apart at all times.
- float restLength = 50;
- physics.makeSpring(anchor, node, strength, damping, restLength);
- // make repulsion for new one with every node
- for(int i = 0; i < physics.numberOfSprings(); i++) {
- Spring s = physics.getSpring(i);
- Particle a = s.getTheOtherEnd();
- strength = 10;
- float minimumDistance = 10;
- physics.makeAttraction(a, node, strength, minimumDistance);
- }
- }
1