Firstly, when working with already existing PVectors instead of doing a = b.copy() you can do a.set(b), which may make some code slightly cleaner. For example n.pos = n.origin.copy().add(force); can be written as n.pos.set(n.origin).add(force); This also has the benefit of not creating a new unnecessary PVector instance.
Secondly, you could slightly optimise the force calculation by doing
Looks cool! One thing I'd like to note is that took me a really long time to understand your calcForce method, since you have a variable called "force" in it that is inversely related to the final answer...I kept trying to figure out how "force" got bigger as the objects got closer together.
9
u/020406code Oct 25 '20
Here's the code: https://020406.org/processing/pde/GridDistortion.pde