This black oil is the reason I code. Not literally but it has had a profound impact on what I find myself coding. In 2002, I bought a small amount of ferrofluid off the internet. It was around the time when I started to learn Processing. I began asking for advice on the Processing forum on how to translate the formulas for magnetism into code. I received a great deal of help and after a couple days, I had a working 2D prototype. I have been using some version of this prototype ever since. You can see the prototype here but it was written for a pre-beta Processing so the code is pretty old. If you are looking for source code, I recommend Shiffman’s tutorial on forces.
The reason the black oil appealed to me was that it allows you to visualize the invisible field surrounding magnets. Its like a three dimensional execution of the iron filings test but much more mesmerizing. I instantly wanted to know more about them. Why do they behave the way they do? Why are they spaced out just so? What insane amount of math is going on behind the scenes?
I recently came across a similar looking phenomenon when looking for late night distraction on YouTube. Cymatics is described by wikipedia as being “the study of visible sound and vibration”. Below is an image of how vibrations from audio can create non-newtonian structures in a cornstarch and water solution.
If I wanted to create a similar looking structure, I would fill a space with magnetic particles (which would all push away from each other) and corral them with a central gravitational force (which would pull them all towards the center). It would look like this:
It is not a bad solution, but it doesn’t really have any personality. It just looks like the result of a circle-packing exercise. Not only that, it isn’t descriptive of the process I am trying to model. With the ferrofluid, there was no central gravitational force tying everything together.
Recently, I revisited the magnetism code. Somewhere in a flurry of ‘what if‘ guesses, I tied the mass/charge ratio to the particle’s distance from the origin. It ended up working surprisingly well.
As a particle moves towards the center, it would gain mass. If it moves towards the edge of the threshold, it loses mass. I added a hint of Perlin noise to break up the circular boundary. It is mesmerizing to watch the particles fall into place. Something about it feels right.
The next step was to disguise these particles. I added them to the multitouch project I have been working on (which I will talk about in my next post). In addition to the goo being distorted by touch, it can now be distorted by the magnetic particles. Every particle tells the mesh at the corresponding location to distort itself by an amount equal to the mass of the particle. Additionally, each particle creates large but shallow surface ripples. Again, the larger the mass, the larger the ripple. This creates a lens distortion which keeps the mesh surface dynamic.
This project also uses webcam input as a simple environmental reflection. I realized I could get a simplified subtle global illumination effect by having the webcam pull in color and brightness directly from the output, creating a highly decaying feedback loop. In short, I draped a piece of white paper over the laptop webcam so that the camera only saw light coming off the monitor.
Here are a couple short renders. They reflect realtime performance. I hope to have videos with audio soon.
Next up, I will talk about the process I used for creating the goo itself. Perhaps eventually, I will be able to code my own cornstarch monsters. Stranger things have happened.