Sound wave sandbox

I wanted to be able to visualize how continuous pressure waves interact within a medium, so I made this little toy in Processing.

Move the mouse around to disturb the medium. Try moving at exactly the speed of sound to build up a shock wave (sonic boom!) in front of you, or shaking in place to send out waves like a speaker. If you make little circles, you’ll produce a spiral wave front which I think is similar to the way orbiting black holes emit gravity waves.

http://www.openprocessing.org/sketch/155458/embed/?width=750&height=850&border=true
This is basically a field of dots whose size and color represent a measure of the pressure at that location in the medium. The cursor acts as a constant source of impulses which travel through it as expanding circles at the speed of sound. If the cursor is held still for long enough, the system settles into something like an average pressure evenly distributed throughout. Because of this set point, a mouse movement will result in two visible wave fronts – a higher-pressure one in the direction of motion, and a lower-pressure one opposing it. I’m not sure if this is actually physically accurate, as it’s being caused by the movement of these concentric circles rather than the medium’s movement towards neutral pressure. It looks about right to me though, and I think it’s probably a reasonable approximation (ignoring the fact that my waves impossibly maintain a constant pressure as they travel).

I really enjoy making sonic booms and spiral wave fronts with this, and it was a ton of fun to program! The code is available at OpenProcessing if anyone would like to take a look: http://www.openprocessing.org/sketch/155458

I’m sure there are ways I could streamline it, I’m still not too familiar with best practices for code efficiency in Processing. If anyone has suggestions for techniques, or things to add to this toy please let me know!

Leave a comment