Coding, Geometry Joys, JavaScript, Murderous Maths, Physics, Uncategorized

Oscillation and Drag Force: Spring Project.

Today Simon was watching Daniel Shiffman’s tutorials to learn about drag force and how to apply it when building a spring simulation in p5.js. Simon wrote the formula for drag force in Microfost Word and looked up all the variables:

Drag Force 23 Apr 2017 2

While building a spring in p5.js, Simon talks about the 3 laws of Isaac Newton:

The project is based upon Daniel Shiffman’s book The Nature of Code, specifically Chapter 3 (Oscillation). Simon spent the rest of the evening studying “simple harmonic motion”, periods and amplitudes. Here is an excerpt from Daniel Shiffman’s book:

y = sine(x)
You’ll notice that the output of the sine function is a smooth curve alternating between –1 and 1. This type of a behavior is known as oscillation, a periodic movement between two points. Plucking a guitar string, swinging a pendulum, bouncing on a pogo stick—these are all examples of oscillating motion.
This is what is known as simple harmonic motion (or, to be fancier, “the periodic sinusoidal oscillation of an object”). It’s going to be a simple program to write, but before we get into the code, let’s familiarize ourselves with some of the terminology of oscillation (and waves).
Simple harmonic motion can be expressed as any location (in our case, the x location) as a function of time, with the following two elements:
  • Amplitude: The distance from the center of motion to either extreme
  • Period: The amount of time it takes for one complete cycle of motion
Looking at the graph of sine, we can see that the amplitude is 1 and the period is TWO_PI; the output of sine never rises above 1 or below -1; and every TWO_PI radians (or 360 degrees) the wave pattern repeats.
Coding, JavaScript, Physics

Sound Visialization

Simon has followed another batch of wonderfully enriching tutorials by Daniel Shiffman on p5.js, this time all about sound, and made these sound visualisations. The first one is based on the Amplitude Analysis tutorial (the amplitude of a song (any sound input) is being analyzed to control elements of a p5.js sketch):

 

The next project comes from the Microphone Input tutorial:

 

Graphing Amplitude tutorial (using the getLevel() function from the p5.js Sound Library to graph the amplitude over time):

 

And the Frequency Analysis tutorial, analyzing the frequencies (spectrum array) of a sound file. Simon created a “graphic equalizer” like visualization. For this project he used the p5.FFT object from the p5.js library. FFT (Fast Fourier Transform) is an analysis algorithm that isolates individual audio frequencies within a waveform.