Flock with ObstaclesThis 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:
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. |