Nature of Code

Week 2: Vectors & Forces

This week I experimented with createVector() and applying forces to objects in p5.js.  I began by making a simple bouncing ball with an acceleration down to simulate gravity (Figure 1). 

Figure 1

Then I converted the acceleration to a gravity force and used an applyForce() function to apply gravity.  With this setup, I could add additional forces to the ball like a wind force with the click of my mouse (Figure 2).  The code for this example can be found here.

Figure 2

From here I created many instances of balls falling and incorporated mass into the acceleration equation.  This created a nice rain effect (Figure 3).

Figure 3

For my final sketch I used these concepts to create a repelling field.  As the mouse moves through a field of particles, they experience a repelling force away from the mouse.  The code for this example can be found here.  Some examples of this sketch are shown in Figure4&5

Figure 4

Figure 5

Eva Philips