19 Feb

clavichord 4: electrostatic charge

To simulate air molecules, I’ve added particles to the simulation. These are tiny light molecules that will bounce off the clavichord (once that’s simulated) so I can measure the vibration of the air molecules and extract a sound simulation from that.

simulation of 2000 particles

To make sure that the particles actually bounce and don’t just pass right through each other, it was necessary to add another force to the simulation, the electrostatic force. With this, I can give all particles a “charge” which will either attract or repel other particles.

To start with, I’ve set all particles to have a positive charge, which causes them all to try to stay away from each other.

To keep the particles within a defined area (so they dfon’t just fall down off-screen forever) I’ve also added a “boundary”, which simulates an invisible box which keeps everything inside it. The particles bounce off the walls, losing a little bit of velocity as they do so.

Doing this in JavaScript is tricky – with only 2,000 particles, the simulation slows down to a crawl. I may need to look into how WebASM works, or whether it would be quicker to use WebWorkers to run the physics in the background.

Demo with only 200 particles.

I think the next step is to move onto 3 dimensions.

Leave a Reply