Nature of Code book: PVector Spring example

I’m working this week on Chapter 3 of my upcoming Nature of Code book. For the most part, if you are looking to connect particles with springs, I recommend the wonderful verlet physics of toxiclibs, and I have some examples for that here. Nevertheless, I am including an elementary implementation of a single “bob” connected to an “anchor” point via a “spring” force. The example implements Hooke’s Law (Spring Force = -k * displacement) with the PVector class, using the Euler integration model of all my other examples. Here it is below.

Source: _03spring.zip

  • Richard van Duijn

    Hi Daniel!

    First of all thanks very very much for all the excellent examples for processing! I’ve been able to create some very nice apps using your examples and processingjs. BUT… I’ve got a quick question.I’m desperately looking for an example which shows me the use of a Rope instead of a Spring. 

    Basicly what I want to achieve is to keep circles within a parent circle. The parent circle is an Attractor for the children and can move freely around the Center Of Gravity. But this also allows them to escape the boundries of the parent circle. A rope would allow me to keep them in the parent circle at all time.

    Could you help me out! Thanks very much!
    Richard

  • Anonymous

    You’ll want to check out toxiclibs VerletPhysics package.   You can create a rope simulation by connecting a series of springs and you can constrain the maximum length as well.  

    http://www.shiffman.net/teaching/nature/toxiclibs/