Java Flies

Flies is now in JavaScript, link to the code is on the main page. Java flies was my first Java program, as Flies 1.0 was my first C program. It works by having each fly accelerate towards it's two nearest neighbours, which are identified by comparing the distance to the present nearest neighbours with the distance to the nearest neighbours of the nearest neighbours, and randomising a bit to help find new neighbours. Java source. I'm sure it could be optimised by a more proficient java programmer than I, but it appears to be a better implementation of the algorithm than my C version. (Jeff Cragg gave me the idea for the algorithm). It's behaviour can be modified by giving it parameters to replace the default values (via HTML) , as is done for NF (the number of flies) in the html on my homepage. The other parameters are -
  • REVDIST - default 200 - the distance in pixels squared at which the flies repulse instead of attract.
  • ACC - default 0.3 - a float for acceleration (or repulsion) to neighbours.
  • ACCTOMID - default 0.1 - a float for acceleration towards the middle.
  • MAXSPEED - default 5 - a float for the maximum speed (in pixels).
  • BOUNCESPEED - default 0.8 - a float for the bounce speed from walls.
  • default value for NF is 15.
in HTML :

<applet code=flies3d.class width=250 height=250>
<PARAM NAME=NF VALUE="9">
<PARAM NAME=MAXSPEED VALUE="7">
</applet>

PS - download flies3d.class for the class file.

Return to my homepage