Every dancer picks one friend and one enemy. At each step dancers shrink a little toward the middle of the floor, take a big step toward their friend and a small step away from their enemy, and now and then they change their minds and pick again.
This rule comes from a 2012 post by Simon Woods on Wolfram Community. I ported it to WebGPU and scaled it up from thousands of dancers to millions.
What makes it work is that there’s no neighbourhood at all. Woods found that searching for nearest neighbours was too slow, so he let every particle react to just two others, wherever they happen to be, and the whole look of the swarm comes out of that one choice.
What I did#
Simulation, point drawing and glow all run on the GPU, in WGSL compute and render passes. The page itself is plain ES modules, about 2,100 lines of JavaScript, with no dependencies.
You can set how many dancers there are (from 10,000 to 4 million), who picks whom (random, rings, cliques, local), 2D or 3D, step sizes, colours and trails, and you can push dancers around with the pointer. All of the state goes into the URL, so if you send someone a link, they’ll see exactly what you saw. In my benchmark with 4 million dancers the median was about 124 frames per second.
You need a browser with WebGPU: Chrome or Edge 113 and later, Safari 26 or Firefox 141.