Games from Nothing: Group Game #2 — Particle Synthesizer

I’ve been applying the aspects of the hider/seeker code with particle systems to create interesting particle systems that are fun to manipulate around on screen. At one point I got the idea that it would be really cool if the particles were somehow generating audio based on their position, or other aspects of their movement. Enter a little research into the Beads extension for Processing, and a couple of headaches, along with having to sacrifice the ability to run on Android for Java only (right now).

I’ll start by discussing the motion built into the program:

sketch

^^ Here’s what happens when you click or hold your finger onscreen. The variable controlling the ‘force’ of the seeking motion of the particles increases to 10, and their speed increases to 60. This causes the particles to ‘tighten’ in towards the mouse cursor and form a tighter ball. The color of the particle also changes to lighter colors. The colors are generated within random ranges, so they appear to have diversity. They also fade as they get older and the alpha value decreases.

sketch2

^^When the mouse or tap is released, the force and speed decrease in value, which causes the particles to ‘back off’ of the cursor and form much wider archs. Their colors also change to blue tones. For me, the system by which the particles seek has enough ‘wiggle room’ to invite play, and to get the particles to do interesting things. Haven’t playtested.

sketch4

The audio is handled by creating a sin wave and a series of harmonics for each particle. The frequency of the fundamental of each particle is dictated by it’s position from left to right on the screen. Far left is lower, far right is higher. As they move down, the particles increase in volume (currently un-intuitive and needs to be refined), and as they move up, the particles decrease in volume.

At first this generated pure noise… There were so many different frequencies playing at once, it sounded like a swirling of air… It was awesome because it made the particles seem like some kind of living, air-breathing, reactive organic object. BUT it wasn’t good for making music.

I solved this by breaking up the x-axis into zones which play specific frequencies if the particles fall into them. This allows me to ensure that the particles have a harmonic relationship, and will create a more ‘pleasing’ sound. Here’s the code that shows the breakdown of frequencies.

if(xpos<0) xpos = 100;
if(xpos<200 && xpos>0) xpos = 200;
if(xpos<400 && xpos>200) xpos = 250;
if(xpos<600 && xpos>400) xpos = 300;
if(xpos<800 && xpos>600) xpos = 350;
if(xpos<1000 && xpos>800) xpos = 400;
if(xpos<1200 && xpos>1000) xpos = 450;
if(xpos<1400 && xpos>1200) xpos = 500;
if(xpos<1600 && xpos>1400) xpos = 1000;
if(xpos<1800 && xpos>1600) xpos = 2000;
if(xpos<2000 && xpos>1800) xpos = 3000;
baseFrequency = xpos;

Author: Jonathan Lloyd