We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I would like to give particles a repulsion force from each other that is proportionnal to distance (inverted gravity) using toxiclibs. How can I do so ?
Consider the code below:
add_library('toxiclibscore') add_library('verletphysics') from toxi.physics2d import VerletPhysics2D from particle import Particle def setup(): global particules, n_particle, physics size(800, 600) physics = VerletPhysics2D() particules =  n_particle = 10 for e in range(n_particle): radius = 100 angle = TWO_PI / n_particle x = radius * sin(angle * e) + map(noise(random(-20, 20)), 0, 1, -20, 120) y = radius * cos(angle * e) particules.append(Particle(width / 2 + x, height / 2 + y)) for e in particules: physics.addParticle(e) for e in range(n_particle - 1): a = particules[e] b = particules[e+1] s = VerletSpring2D(a, b, 40, .2) physics.addSpring(s) a = particules[-1] //// connect the last particle to the first making a loop b = particules s = VerletSpring2D(a, b, 40, .2) physics.addSpring(s) def draw(): global particules background(0) for e in particules: e.display() physics.update()
In setup() if I add something like:
for e in particules: for f in particules: if e != f: force = PVector.sub(e.location, f.location) distance = force.mag() physics.addBehavior(AttractionBehavior(f, 10, -1 / distance ))
... the behavior will be fixed and won't change over time. What I need is a repulsive force that constantly changes depending on the varying distance between 2 particles. I tried to put that snippet in draw() but the forces kept accumulating and I couldn't figure out how to cancel them at each iteration.
Any idea how I can implement this kind of adaptative behavior with toxiclibs ?