Inspired by Clusters by Jeffrey Ventrella, whose source is obfuscated, so I'm not sure how it works exactly, but going from some hints - the linked page references Lynn Margulis' work on endosymbiosis in bacteria and mitochondria - I only suspect it's something like this...
Each colour represents a species. There are a number of different substances. Each species produces some substances, and consumes some substances. At each time step, each organism is attracted to those others producing substances that it needs. Each production and consumption factor is signed, when negative they repel instead of attract. There is a small repulsion for all organisms when they get too close to each other. All the organisms are confined in a 3D ball, they bounce off the boundary. There is a small amount of friction too.