A little boids applet

Steve's aquarium

Hello, welcome to the latest evolution of my flocking demo. If the applet doesn't run on your browser, don't be alarmed, it's just because you aren't using the same one as me. If you want to know what the hell all these triangles are doing moving about your screen click here.

I recently installed a copy of Symantic Visual Cafe 2.0, which was on a PC Plus magazine cover CD. A really good development system for free, unbelievable! Thus inspired I dickered around with my applet removing the nasty floating control panel, and adding a couple of new features (well one actually). Of course since the slider controls are Symantic supplied classes, one of the side effects of this effort was to quadruple the size of the program. Another was to make version 1.1 of Java a must in order for the applet to run. I suspect that these effects combined will reduce the number of people who actually get to see the applet working to a small minority of the 100 or so people a week who actually look at this page. Well I'm not changing it back now.

For the ten or so people a year who mail me about this demo, here's my frequently asked questions list.

Q: Can you make the shark eat the fish?

A: Yes, I could but it just makes the fish gradually reduce in number until there's only one left. It doesn't make the demo any more interesting.

Q: Wouln't it be good if you could feed the fish?

A: Well I tried it, it's boring, so I took it out.

Q: Can I have a copy of the source code?

A: Yes. It's a mess. God alone knows why you want it.

The fish follow the three classic incentives in flocking algorithms; they try to steer towards the average position of their neighbours (Cohesion), they try to point in the same direction as their neighbours (Alignment), and they try to avoid one another (Separation). In addition, in this simulation they have a slight tendancy to steer towards the central horizontal plane, and of course they avoid the shark like crazy.

The control panel allows you to change the three main parameters which control the fish behaviour, and also how they are displayed. In each of the 'Cohesiveness', 'Alignment' and 'Separation' box pairs, the first number determines the range over which the parameter operates, that parameter is divided by the second (the Divider) to give a value which is used to determine how rapidly the fish try to change direction. For 'Avoidance' and 'Alignment' the first number is inverted, in order to make the impulse weaker from a distance.

For example, you can create more of an insect swarm effect by entering a low Divider value for Cohesiveness.

If you increase the number of species, the fish will apply the cohesiveness and alignment rules only to members of their own species. They will still avoid all other fish.

Another important facet of the flocking algorithm is the limited ability of an individual to see its neighbours over a distance. Somewhat counter intuitively, this needs to be kept pretty low for the flocking to be sastisfactory. You can play with this by entering alternate values for the 'Neighbour Distance' parameter. You will soon see what I mean.

'Speed', 'Number of Fish' and 'Camera Distance' are all pretty self explanatory I think Lower speeds produce quite satisfying results.

If you like the applet, or want to use the source code, or if it doesn't work at all, do mail me.