Flock with Obstacles

This is a flocking simulation that I wrote for the Java portion of a four-language computer course: lisp, ML, Prolog, and Java. This applet is pretty pathetic in most respects. Java's random number generation is a sorry excuse for true randomization. In addition I dispensed with screen double-buffering because that slows the animation down considerably, and the neighbor tracking falls to pieces as the edges of the torus wrap around. To top it off, this is an N-squared flocking algorithm. I just didn't spend any time implementing my more complex algorithms for this particular assignment. To see some truly impressive flocking programs I recommend you take a look at my two C++ flocking simulations: Mega Flies and Gnat Cloud.

A quick rundown of the GUI components:

  • Population: the population, duh
  • Number of Neighbors: number of nearest neighbors used to navigate
  • Max Speed: max speed allowed; also the "goal" speed used to motivate movement
  • Proximity: is an attempt made to stay near (but not too near) neighbors
  • Velocity: is an attempt made to align velocity (speed and direction ) to neighbors
  • Restart: start over
  • Quit: end the simulation

Clicking or clicking and dragging the mouse inside the map will paint obstacles for the flock to deal with. A small glitch: the labels, checkboxes, and buttons have a tendency to disappear if you pass the mouse over them. Forcing the window to redraw (by minimizing or windowshading the window) fixes this problem. Have fun, and be sure to check out the other Java simulation I wrote as part of the same assignment, Gravity.

ALT= "Applet could not be loaded" Sorry, it is time to upgrade your browser to a Java powered one.