We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I've recently found this article from Zachary Lieberman where he provides some insights on his work. I'm particularly interested in his "recipe" to make a blob moving "organically" (almost like a fluid).
This is a 2-step process:
- connect particles with springs (and connect the last particle to the first particle, making a loop)
- give the particles a repulsion force from each other that is proportional to distance (stronger force when closer) and has a maximum radius for interaction (i.e., if particles are beyond this distance, they don’t have an impact on each other)
I made both a particle and a spring class but got lost when trying to implement the repulsion force. What should I change (add ?) in the following snippet (a spring class using basic Hooke's law) to "give the particles a repulsion force from each other that is proportional to distance" ?
class Spring(object): def __init__(self, x, y, l): self.startpoint = PVector(x, y) self.constant = .2 self.lngth = l self.g = 10 self.mass = 4 def connect(self, p): # p refers to the particle_class force = PVector.sub(p.location, self.startpoint) distance = force.mag() stretch = distance - self.lngth force.normalize() force *= -1 * self.constant * stretch # Hooke's law force.limit(.4) p.applyForce(force) def displayLine(self, p): stroke(255) strokeWeight(1) line(p.location.x, p.location.y, self.startpoint.x, self.startpoint.y)
On a side note, I'm also curious to know how to display particles following a splatter shape (GIF above).