About
Software
Services
Ideas
Rants
nklein logo

Swarm

Overview

You've probably seen screensavers like xswarm. In xswarm, a wasp runs around the screen randomly. A bunch of bees follow it. The bees don't have quite the turning radius that the wasp has, so they flow nicely behind the wasp.

Now, ask yourself, would the wasp really fly around in two dimensions like that if it had a herd of bees after it? ``His pattern indicates two-dimensional thinking.''

The nklein software angle is: ``Of course! If you gave that wasp 144 dimensions, it'd make good use of them.''

This program allows a the wasp to wander around in a given number of dimensions followed by a given number of gnats (sorry, we chose ``gnats'' instead of ``bees''). The output of the program is a stream whose width is the number of dimensions. The value of the pixels on each line of the stream are directly correlated to the distance from the origin of the positive average coordinates.

What really goes on is this.... during each pass, the position of the wasp is updated and the positions of the gnats are updated. The wasp is trying to get to a particular point in n-space. Every so often, the wasp's target point changes.

After the positions are updated, the average position of the wasp and all of the gnats is calculated. If the -abs option was specified, the absolute value of these average coordinates is taken. Each coordinate is multiplied by the gain and then clipped to the range [0,255]. Those values are output as unsigned characters in order from lowest numbered dimension to highest numbered dimension.

Here is some sample output from the swarm (rotated so that time increases from left to right): swarm picture

Options

[-lines lines]
The number of lines of output to generate. The default is zero, which means generate lines forever.
[-dims dimensions]
The number of dimensions to allow the wasp to wander in. This ends up being the width of the stream generated. The default value is 32.
[-gnats gnats]
The number of gnats following the wasp. The default value is 7.
[-mv maxVelocity]
The maximum velocity the wasp can achieve. Unfortunately, the gnats fly at speeds that are randomly centered around 29 units per second. But, there is no way to change that. The default value is 30.0.
[-ma maxAcceleration]
The maximum acceleration the wasp can achieve. Again, the maximum acceleration achievable by the gnats isn't specifiable. The default value is 10.0
[-af accelerationFactor]
This determines how much the wasp tries to accelerate based upon its distance to the destination point. It also affects how hard the gnats try to accelerate to get to the wasp. The default value is 1.0.
[-pd pointDuration]
This is how many seconds it is before the wasp changes its destination point. The wasp also changes destination points if it gets within ten units of the destination point. The default value is 1.5.
[-lps linesPerSecond]
This tells the swarm program how many lines of stream output should be generated for each second of wasp and gnats time. The default value is 32.0.
[-gain gain]
A scaling factor for the output. The default value is 10.0.
[-seed s1 s2 s3]
Numbers to seed the random number generator. These should be 16-bit numbers specified in hex. The default value is created based upon the process id and the current time.
[-abs]
Tell the program to take the absolute value of the coordinates before doing the clipping to [0,255].

(copyright 2001) (gpg keys)

Valid XHTML 1.0! Valid CSS!