In Affinity, https://codepen.io/scudly/full/aBdqpb, each entity has a hue and has an affinity to other entities with similar, though not quite the same, hues and flees from those with a different hue.
The overall behavior of the swarms results from a complex balance between the density of the entities, based on their number and the world size, their speed, and their view radius. dt is the delta time that affects the overall speed. Each entity’s speed is capped by its brightness – set it to 1.0 and they all act identically. Play with the numbers to see different effects.
Post replies if you come up with any fun variations, especially if you add any new behaviors.