We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
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[0]
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 ?
Answers
isn't this the same as your other question?
if you have multiple questions you'll split the answers and confuse everybody. better to keep it focused in one place.
@koogs No it not the same question ! One was about applying a repulsion force to a particle system without using any library and the new one is about giving a repulsion force to particles individually and using the toxiclibs library. All this was well explained in the question you deleted.
@koogs This question is NOT answered ! Please stop deleting or avoiding my questions, you're wasting my time and my energy. I'm putting a lot of effort trying to explain the problems I'm facing in a language that is not my mother tongue.
It's been almost a week that Im trying to make a blob moving in Processing and nobody cares about my questions.
This forum is all I have, so please read carefully what I wrote before deciding to remove my questions. You'll see that every question I asked is different as I'm trying different approaches. And I'm trying different approache because no one answered my original questions.
how is this NOT the same thing?
your main problem here is this:
this cuts down the number of people here who can answer your questions by about 90%
this cuts that remaining 10% by 90%
and again.
@koogs: Applying a fixed repulsion force to a whole particle system is not the same thing as applying a changing force to particles individually. Not to mention that one question was about doing it without library, and the other one with the toxiclibs library. I perfectly understand that very few use the Python mode and that even less people understand how the toxiclibs library works. That's why I asked the help of GoToLoop who, unfortunately for me, doesn't seem to be interested.
http://ToxicLibs.org/docs/verletphysics/toxi/physics2d/VerletParticle2D.html
http://ToxicLibs.org/docs/core/
http://ToxicLibs.org/docs/verletphysics/
@GoToLoop Thank you for taking the time to comment my question. I understand you did a lot of research to help me and I'm truely thankful to you for that.
I've read the API and particularly the 5 classes you mentionned, many times, again and again, but couldn't make much sense of it to be honest. It seems quite difficult (near impossible ?) to have some control on a toxiclibs behavior as the sketch is iterating.
All I've managed to do is adding a static repulsion + attraction force beforehand.
https://media.giphy.com/media/1k2wspz8guv3PZ7dYq/giphy.gif
But, again, the repulsion force should be proportional to distance thus changing over time, as particles get closer or farther at each iteration.
Although you're not familiar with the toxiclibs library, if you have any idea/supposition on how I can make that repulsion force work (with or without toxiclibs), I would really love to hear it.
^:)^
Particle class
Anyone ?