It has been 12 years since @simon-woods created this fascinating animation an invented a boids model which is more efficient than typical ones. Code is extremely short an elegant:
n = 1000;
r := RandomInteger[{1, n}];
f := (#/(.01 + Sqrt[#.#])) & /@ (x[[#]] - x) &;
s := With[{r1 = r}, p[[r1]] = r; q[[r1]] = r];
x = RandomReal[{-1, 1}, {n, 2}];
{p, q} = RandomInteger[{1, n}, {2, n}];
Graphics[{PointSize[0.007], Dynamic[If[r < 100, s];
Point[x = 0.995 x + 0.02 f[p] - 0.01 f[q]]]}, PlotRange -> 2]
QUESTION: post modifications of this code that produce NEW interesting behavior. Modifications can range from simple parameter change to completely different code of boids. The only requirement is the boids behavior should be somehow different. The most interesting behavior / animation wins.
Simon's explanation:
The latest way I have found to use my expensive math software for frivolous entertainment is this. Here's is a way to describe it.
- 1000 dancers assume random positions on the dance-floor.
- Each randomly chooses one "friend" and one "enemy".
- At each step every dancer
- moves 0.5% closer to the centre of the floor
- then takes a large step towards their friend
- and a small step away from their enemy.
- At random intervals one dancer re-chooses their friend and enemy
Randomness is deliberately injected.
Background: I had read somewhere that macro-scale behaviour of animal swarms (think of flocks of starlings or shoals of herring) is explained by each individual following very simple rules local to their vicinity, essentially 1) try to keep up and 2) try not to collide. I started trying to play with this idea in Mathematica, but it was rather slow to identify the nearest neighbours of each particle. So I wondered what would happen if each particle acted according to the locations of two other particles, regardless of their proximity. The rule was simply to move away from one and towards the other.
The contraction (x = 0.995 x) was added to prevent the particle cloud from dispersing towards infinity or drifting away from the origin. I tweaked the "towards" and "away" step sizes to strike a balance between the tendency to clump together and to spread apart (if you make the step sizes equal you get something more like a swarm of flies). With each particle's attractor and repeller fixed, the system finds a sort of dynamic equilibrium, so to keep things changing I added a rule to periodically change the attractor and repeller for one of the particles. The final adjustment was to make the "force" drop towards zero for particles at very close range. This helps to stop the formation of very tight clumps, and also prevents a division-by-zero error when a particle chooses itself as its attractor or repeller.
The description of the system as a dance was an attempt to explain the swirling pattern on the screen without using mathematical language. I'd love to see what other "dances" can be created with other simple rules.








