[image of digits]

Flocking Canvas->Polygons
Embarcadero C++ Builder Applications

©All source code, applications and images on this page, or accessed from this page, are Copyright © Nicholas Gessler and/or on behalf of those who created them.

Do not assume that all code blocks in any one application are entirely compatible with the code blocks in other applications.
Please verify the compatibility yourself before you cut-and-paste.

TO DO:

  1. Specific visualization shapes for agents: hexagons, stars, polygons...
  2. Manage agent births and deaths.
  3. Adapt nearest neighbor functions for toroidal space.
  4. Introduce nearest neighbor functions that discriminate between different types.
  5. Create zoned pie-shaped visual fields weighing those ahead and behind you differently.
  6. Implement predator / prey scenarios.
  7. Implement age, sex, hunger, and exchanges of local and global information.

TO DO:

  1. Generate statistics on multiagent behavior.
  2. Allow user to enter values in all Edit boxes.
  3. Implement traffic flow expecting retrograde congestion waves.
  4. Implement gestures.
  5. Implement memory of encounters to build social networks.
  6. Implementing Sugar-Scape trade in resources.
  7. Enable interaction with an environmental map (Digital Elevation Model or BMP image).

x

x
x
x
Nice models I & 2 (Hal Levison, Southwest Research Institute, Boulder, Colorado). Sky & Telescops. Kirkwood Gaps (based on a plot by Alan Chamberlain, JPL/Caltech, California posted on Wikipedia). Jupiter Trojan (red & green) and Hilda (white) family of asteroids (Pulkovo Astronomical Observatory, Russian Academy of Sciences, St. Petersburgh. Horseshoe orbits and the 5 Lagrage points (Xander talk 1989, NASA).

Data set for the above four screen shots: Jupiter 6548231.txt


XE6 - Flocking / Orbits - Version 40 - Nick Gessler - 7 October 2016

Improvements:

  • Rule 20: Mars and Jupiter each interacting with the Sun but not with one anoher.
    Their relative masses are exaggerated in the proportions 0.1, 0.3 and 1.0.
  • Rule 21: Jupiter interacts with the Sun.
    Jupiter's relative mass can be set to 0.001 (accurate), 0.02 or 0.30.
  • True orbits for Mars and Jupiter were calibrated using 700 agents launched eastward.
    Mars: radius 123 pixels (1.520 AU), agent 107/700, velocity dX = 2840.
    Jupiter radius 420 pixels (5.200 AU), agent 538/700, velocity dX = 1546.
  • Counterclockwise orbits have been implemented.
  • Asteroids may be inserted as a ring of magents with a given velocity and distance in AU.
  • Screenshots may be automatically saved each Jovian year. Be careful, since each screen shot is 5Mb in size.

Some orbital resonances to explore (AU values are entered as thousandths):
For stable circular orbits, velocities are computed as 110,731 or 111,484 divided by the square root of AU.

  • Resonance 6:5 set AU = 4606 (4.606 actual) and velocity = 1635 to 1643.
  • Resonance 5:4 set AU = 4482 (4.482 actual) and velocity = 1658 to 1665.
  • Resonance 4:3 set AU = 4293 (4.293 actual) and velocity = 1694 to 1701.
  • Resonance 3:2 set AU = 3969 (3.969 actual) and velocity = 1762 to 1770.
  • Resonance 2:1 set AU = 2974 (2.974 actual) and velocity = 2035 to 2044.
  • Resonance 3:1 set AU = 2500 (2.500 actual) and velocity = 2220 to 2230.

Important variables and functions (line numbers may differ from the present version).

XE6 - Flocking / Orbits - Version 37 - Nick Gessler - 20 October 2015

Improvements:

  • Ghost triangles have been removed.
  • Martian and Jovian orbits are now "true."
  • Orbital "repulsors" have been instantiated.
  • Some Unicode symbols have been incorporated
  • "Drop agents from top of screen" has been implemented.
  • "Fall to Earth" has been implemented.

Some important variables and functions.

x
Martian and Jovian orbits are now "true." Mars (red orbit) now captures one moon. Note the displacement of orbits away from Jupiter.

xx
Traffic / Explode from cursor.

xx
Drop agents from top of screen between two suns. / Explode from cursor while avoiding nearest neighbor.

xx
Traffic variations.

XE6 - Flocking / Orbits - Version 35 - Nick Gessler - 18 March 2015

The control panel has been enlarged and slightly modified.
Three "Evolve" mechanisms have been implemented:

  • Evolve Random - New asteroids are introduced with random speeds, directions and positions.
  • Evolve Clockwise - New asteroids are introduced clockwise from the radius at random velocities and positions.
  • Evolve Launch Velocity - New asteroids are introduced clockwise from the radius at random
    positions with uniform speeds selected by the user

A Measure Radius feature (the twohorizontal white lines) has been added for confirming circular orbits.

Flocking / Orbits - Version 34 - Nick Gessler - 2 April 2014

A new "Auto Run" function has been implemented.
All "Launches" are in agent.Tag order and are equally distributed.
A "Traffic" rule has been included (agent.seeking must be set to "Next").
Shown to left is one of the many configurations resulting from "Launches" with non-orbital rules.

Flocking / Orbits - Version 33 - Nick Gessler - 26 March 2014

When "Space" is set to "Evolving," the number of new asteroids thrown in is also counted.

The orbiting rules have been renumbered and a modification has been made to the orbits in the
"Orbit Sun, Mars Jupiter" rules.

"20 Orbit Sun, Mars, Jupiter 1" retains the exaggerated masses of 1.0, 0.1 and 0.3 respectively.
"21 Orbit Sun, Mars, Jupiter 2" uses more realistic masses of 1.0, 3.2x10-7 and 7.2x10-4 respectively.
However, with #2 gravitation is so low that tuning becomes even more critical.

You can now "Launch" asteroieds from Mars, from Jupiter and from multiple points along the radius.
You can also set the velocity at which those asteroids will be launched.
The asteroids will all be equally distributed.

The "Launch Asteroids" velocity is presently fixed.
Using "18 Orbit One Sun" and a population of 700 asteroids, by varying the gravity,
one can obtain
perfectly circular orbits of varying diameter as in the table below. Note that by adjusting the coloring
of asteroid speed, one can judge a perfect circle by its uniformity of color.

Gravity
Agent (Tag)
Oribtal Diameter (cm)
150
79
1.8
217
59
2.7
300
112
3.8
399
164
4.8
488
230
6.3
598
283
7.3
698
346
9.0
806
407
10.0
905
474
11.4
1005
527
12.5

Ideally, for a given gravity, we would like the launch velocities that give perfect circular orbits at different radii
so that the "Launch Asteroids" button will ultimately launch all asteroids into circular orbits.

For the data from a four-hour run click here.

Flocking / Orbits - Version 32 - Nick Gessler - 18 November 2013
3D has been improved by changing the visualization to a constant size triangle.
A spiraling-upwards rule has been added. Reduce the population and equalize agent depth for a clearer view.
The impact Mars and impact Jupiter events have been debugged. A trackbar should be added to set the magnitude of the impact.

The image to the left shows the result of the impact on Mars event.

For the data from a four-hour run click here.

x

Flocking / Orbits - Version 31 - Nick Gessler - 11 November 2013
Autorun (the screen can be cleared every 15, 30 or 60 seconds) with Solar System Resonances
Asteroids orbiting the Sun (rule 17), two binary Suns (rule 18), and the Sun, Mars & Jupiter (rule 19).

Tracking has been improved by shift-wheel-clicking to identify a single agent to be rendered.
The controls have been more conveniently reorganized
.

The image to the left shows the result of tracking 16 moons of Jupiter that were captured after a six-hour run.
The image is a PhotoShopped composit of the 8 prograde and 8 retrograde moons with the new control panel superimposed.

For a clear view of the composite (without the control panel) click here.

For the data from a four-hour run click here.

 

x
The Sun is the yellow dot.
Mars' orbit is shown by the red/yellow arc.
Jupiter's orbit is shown by the blue arc in what looks like fringe at the right.
The green lines show the orbits of perhaps 20-30 asteroids in the asteroid belt,
many more inside the orbit of Mars,
and 18 captured by and orbiting Jupiter.

x
The Sun, mars and Jupiter are colored as in the image to the left.
The asteroid orbits are colored according to the direction they are travelling.
Although Mars and Jupiter are orbiting clockwise, most of the asteroids are orbiting countercloskwise.
This retrograde motion is surprising since most asteroids in our Solar System travel prograde orbits.

Flocking / Orbits - Version 30 - Nick Gessler - 1 November 2013
Autorun (the screen can be cleared every 30, 60 or 90 seconds)with Solar System Resonances
Asteroids orbiting the Sun (rule 17), two binary Suns (rule 18), and the Sun, Mars & Jupiter (rule 19).

New with this version: Any of up to 100 individual agent asteroids may be tracked.
The target asteroid will render in Green while the others will render in Gray.
To speed up evolution the selected r
endering intervals have been increased.
The initial randomized speeds of asteroids have been slowed.
"Explosions" on the surfaces or orbiting Mars and Jupiter have been tentatively implemented (but incorrectly).


For the orbital rules, space is set to "evolutionary" by default. Once an asteroid flies off-screen, it is returned with a new x, y, dx and dy.
If space is set to "infinite," asteroids that fly off-screen continue their orbits and consume computer cycles
.

Flocking / Orbits - Version 29 - Nick Gessler - 7 November 2013
Autorun (the screen can be cleared every 30, 60 or 90 seconds)with Solar System Resonances
Asteroids orbiting the Sun (rule 17), two binary Suns (rule 18), and the Sun, Mars & Jupiter (rule 19).

SWEET SPOTS IN THE CODE

Flocking Polygons - Orbits Around Three Massive Objects
Version 25 - Nick Gessler - 16 April 2013

A third gravitating body has been added and the POV changed to show the revolution around the main massive object (i.e. Sun). The gravitational attraction of the Sun and planets are different.

To do:
Simulate as well as possible the orbits and gravitational attraction of Mars and Jupiter.
Absorb asteroids that fly too close (at present they fly off the screen).
Introduce the asteroids with circular orbits.
Improve the visualization.

Only some of the "sweet spots" in the code.

Flocking Polygons - Orbits Around Three Massive Objects
Version 24 - Cody Baker - April 2013

A third gravitating body has been added and the POV changed to show the revolution around the main massive object (i.e. Sun).
Since showing a decaying solid trail behind each orbiting asteroid would consume significant computational resources, pixels are randomly turned to black after each iteration. In that manner the trails "fade out" with time.

Only some of the "sweet spots" in the code.

Flocking Polygons - Orbits Around Two Massive Objects
Version 24 - 3 April 2013

Two gravitating bodies influence the orbits of asteroids. The POV has been fixed to hold the positions of those main masses (i.e. Suns) constant. Trails persist but they can be colored to show the position of each asteroid at each iteration. The color TrackBar can expand the color mapping significantly.

Rule #18 has been added to simulate orbits around two massive objects. It works very much like rule #12.
When the sound is turned "off," the two musician agents will no longer be white.

If you click on rule #12 or rule #18, many of the settings will be automatically chosen in order to optimize the visualization.
"Run, Step and Stop" control program flow.
"Randomize All" will reset all parameters and restart the simulation.
Lines will trace the orbits of each planetesimal around a massive Sun at the center of the screen.
Each planetesimal will be colored differently.
The
"Population" TrackBar will change the number of planetesimals in the simulation.
The "Sim Delay" TrackBar will slow things down.
The "Gravitation" TrackBar will vary the gravitational attraction.
You may wish to set "Sound" to "N" for "no" if it becomes annoying.

The speed of a planetesimal will increase as it approaches the Sun.
You may wish to visualize the speed differences within an orbit by selecting "Speed in Colors."
You may then wish to set the "Color Range" TrackBar so that the maximum speed is red.

"Randomize All" will start a new simulation, so pressing this a number of times will show you the range of variation of orbits one might expect to see. Note that the planetesimal agents are given random speeds and directions so that only a few of them will produce ellipses within the display area. Note too that occasionally and orbiting body traces a knot-like path around the Sun. The dynamics are qualitatively correct. However, because of the precision limits of a long double, objects which pass the massive objects in close encounters will be purturbed in their orbits.

Next step: Add Jupiter and Mars and track the perturbations of the orbits of the asteroids and the emergent ring structures. Rule #16 approximating gravitation had been added previously. It should now be deleted.

Only some of the "sweet spots" in the code.


Gallery (click on image to enlarge)
Settings:
Set "Population" to large
Vary "Independence" while the simulation is running
Set "Color Range" to maximum,
Click "Reset"
Press "Assign Next"
Press "Equalize Speed"
Set "Space" to infinite although the pattern may wander off the screen. Other settings have interesting effects
Set "Agent Shape" to line
Set "Agent Color" to iterations color synchronous

Flocking Orbits - Version 23c - 27 March 2013

If you click on rule #12, many of the settings will be automatically chosen in order to optimize the visualization.
"Run, Step and Stop" control program flow.
"Randomize All" will reset all parameters and restart the simulation.
Lines will trace the orbits of each planetesimal around a massive Sun at the center of the screen.
Each planetesimal will be colored differently.
The
"Population" TrackBar will change the number of planetesimals in the simulation.
The "Sim Delay" TrackBar will slow things down.
The "Gravitation" TrackBar will vary the gravitational attraction.
You may wish to set "Sound" to "N" for "no" if it becomes annoying.

The speed of a planetesimal will increase as it approaches the Sun.
You may wish to visualize the speed differences within an orbit by selecting "Speed in Colors."
You may then wish to set the "Color Range" TrackBar so that the maximum speed is red.

"Randomize All" will start a new simulation, so pressing this a number of times will show you the range of variation of orbits one might expect to see. Note that the planetesimal agents are given random speeds and directions so that only a few of them will produce ellipses within the display area. Note too that occasionally and orbiting body traces a knot-like path around the Sun.

The Celestial Mechanics formula is correct and the source code implements it. The question is this: Are the wandering ellipses, the rosettes and the rare tangled orbits realistic? That is to say, do they occur in real life in nature? If not, they may be artifacts of the inprecision of the variables in the calculations. The faster an object moves, the less precisely its position is calculated. Consequently, each close pass by the Sun may introduce an incremental error which would cause the ellipse to rotate. In fact it appears that the closer the orbit passes the Sun, the more the ellipse wanders. On the other hand, calculating positions more precisely should reduce the problem if it is an "artifact." When the "Sim Delay" TrackBar is pushed to the extremem left, the pattern of wanderings does not change. That would seem to argue that the wandering is not an artifact..

We might might minimize this problem by letting the Sun "consume" anything that passes close by. Adding more gravitational bodies if these are "artifacts" of the simulation and we keep them as little as possible, resonances should over-shadow them.

Next step: Add Jupiter and Mars and track the perturbations of the orbits of the asteroids and the emergent ring structures. Rule #16 approximating gravitation had been added previously. It should now be deleted.

Only some of the "sweet spots" in the code.

Flocking - Version 23b - 26 March 2013

A new rule #12 has been added to simulate the gravitational attraction of planetoid agents to the Sun at the center of the screen. When rule #12 is selected, other parameters are set to optimize the visualization. As a shortcut to adjusting the acceleration due to gravity and the mass of the Sun, the "Independence" TrackBar is automatically changed to read "Gravitation." Because no collisions with the Sun are detected, objects which would otherwise crash into the Sun and be absorbed instead pass close by and reach enormous speeds. Consequently, collisions should be implemented. A new square shape for drawing planetoid agents, independent of their speed, has been added for a less confusing visualization. A new visualization has been added to color each planetoi agent by the colorRamp() equivalent of its tag number. A new "infinite" spatial representation has been implemented. The orbits appear to be accurate...

Next step: Add Jupiter and Mars and track the perturbations of the orbits of the asteroids and the emergent ring structures. Rule #16 approximating gravitation had been added previously. It should now be deleted.

Only some of the "sweet spots" in the code.

Flocking - Version 22b - 13 November 2012 - Nick Gessler

Rule 6 "Follow Assigned Individual" now handles several options for who to follow. Who an agent should follow may be set in the "Assign Agents to Follow" control. The "leading" agent may, or may not, follow the cursor. The wandering loop structure illustrated to the left is the result of a low population (e.g. 40), a high independence (e.g. 700) and a visualization NOT based upon speed. "Reset" randomizes almost everything, so any time you press "Reset" or change the "Population" you must then press "Assign Agents to Follow / Next" and "Equalize Speed." Setting the "Space" to "Bounce" eliminates much of the jarring interruptions when an agent goes out-of-bounds.

A rule approximating gravitation has been added. In what ways does it succeed? In what ways does it fail? The force of gravitation is calculated as a variable (set by "Radius") divided by the distance squared. That force is applied as a velocity applied in the direction of the cursor.

The complex global patterns of movement arise from the individual behaviors of up to 700 individuals, mostly following the same local rules of behavior.  Agents begin with random speeds and directions and interact with other agents they can see.  The agents’ perceptual radius, independence, variability and other parameters may be adjusted.  A variety of visualizations and sonifications are possible.  The simulation may be run manually from the gray control panel or automatically by selecting “timers-on,” which will change settings at random intervals.  Right-click the display to recover the manual controls. 

To do: Create a society, a culture, of heterogeneous agents acting at cross-purposes to encourage the emergence of competition and cooperation...

Only some of the "sweet spots" in the code.

Flocking - Version 22a - 8 November 2012 - Nick Gessler

A rule approximating gravitation has been added. In what ways does it succeed? In what ways does it fail? The force of gravitation is calculated as a variable (set by "Radius") divided by the distance squared. That force is applied as a velocity applied in the direction of the cursor.

The rules, function names and variable names have been simplified. The complex global patterns of movement arise from the individual behaviors of up to 700 individuals, mostly following the same local rules of behavior.  Agents begin with random speeds and directions and interact with other agents they can see.  The agents’ perceptual radius, independence, variability and other parameters may be adjusted.  A variety of visualizations and sonifications are possible.  The simulation may be run manually from the gray control panel or automatically by selecting “timers-on,” which will change settings at random intervals.  Right-click the display to recover the manual controls. 

To do: Create a society, a culture, of heterogeneous agents acting at cross-purposes to encourage the emergence of competition and cooperation...

Flocking - Version 22 - 5 November 2012 - Nick Gessler

The rules, function names and variable names have been simplified. The complex global patterns of movement arise from the individual behaviors of up to 700 individuals, mostly following the same local rules of behavior.  Agents begin with random speeds and directions and interact with other agents they can see.  The agents’ perceptual radius, independence, variability and other parameters may be adjusted.  A variety of visualizations and sonifications are possible.  The simulation may be run manually from the gray control panel or automatically by selecting “timers-on,” which will change settings at random intervals.  Right-click the display to recover the manual controls. 

To do: Create a society, a culture, of heterogeneous agents acting at cross-purposes to encourage the emergence of competition and cooperation...

Only the "sweet spots" in the code.

Flocking - Version 21 - 27 March 2012 - Nick Gessler

The complex global patterns of movement in this simulation arise from the individual behaviors of up to 700 individuals, all following the same local rule of behavior.  Agents begin with random speeds and directions and interact with other agents they can see.  The agents’ sight radius, independence and variability may be set with sliders.  A suite of visualizations and sonifications is available.  The simulation may be run manually from the gray control panel or automatically by selecting “timers-on,” which will change settings at random intervals.  Right-click the display to recover the manual controls.  Except for their speed and direction, all agents share a homogeneous set of cognitions and actions. 

To do: Create a society, a culture, of heterogeneous agents acting at cross-purposes to encourage the emergence of competition and cooperation...

Only the "sweet spots" in the code.

Flocking - Version 20 - 8 January 2012 - Nick Gessler

The complex global patterns of movement in this simulation arise from the individual behaviors of up to 700 individuals, all following the same local rule of behavior.  Agents begin with random speeds and directions and interact with other agents they can see.  The agents’ sight radius, independence and variability may be set with sliders.  A suite of visualizations and sonifications is available.  The simulation may be run manually from the gray control panel or automatically by selecting “timers-on,” which will change settings at random intervals.  Right-click the display to recover the manual controls.  Except for their speed and direction, all agents share a homogeneous set of cognitions and actions.  Coming soon: a society of heterogeneous agents forming even more interesting self-organization.

A to-do list for Flocking:

  1. MouseOver or MouseDown to probe an agent
  2. Midi sonification based upon direction for agent nearest to cursor or for a particular agent
  3. Circular race-track
  4. Pipe with friction (what does it require to see eddying effects?)
  5. Resource harvesting: sugar & spice, bread & water, etc.
  6. Color as a function of the agent.
  7. Coloring in shades along only one side of the color cube.
  8. A uniform sized, but still oriented, triangle for all agents.
  9. Doing the rounds: Visit A then B then C then D...
  1. Ghost agents (their influence is felt but they are not seen)
  2. Seek hierarchically: Leader agent A is sought by 3 agents at level B, each of which is sought by three agents at level C, etc.
  3. The above with randomly assigned speeds, or the leaders progressively faster, or the seekers progressively faster.
  4. Complete the 3D functionality.
  5. Unusual neighborhoods of influence: ring, or agents of a certain type, speed, direction
  6. Ranking influence by the degree to which agents are directly ahead of you.
  7. Obstacle avoidance, to include avoiding collisions with other agents.
  8. Math 131 textbook for accessible trigonometry and calculus.

Flocking - Version 17 - AutoRun and FullScreen - 14 November 2011

Several new behavioral and coloring rules have been added.
Hierarchical seeking has been implemented as has equalizing everyone's speed.
Obstacles have been added.
Gray and color rendering has been added based upon iteration, direction and speed.
Iteration coloring for each agent has been desynchronized.
A MIDI sonification has been added.
A TrackBar has been added for agent size.
Shift-Control MouseDown events have been added.

Gallery

Flocking - Version 14 - AutoRun and FullScreen - 8 November 2011

The close button has been eliminated:
* It has been replaced by an "X."
One new color trails option has been added:
* Outline with the same color. (The previous option was incorrect but has been retained.)
Two new rules have been incorporated:
* Seek nearest neighbor.
* Flee larger, seek smaller. (The previous encoding was incorrect.)
The rules are approximately between lines 392 and 869.

Canvas->Polygon Agents - Version 13 - AutoRun and FullScreen
3D (a work in progress) 3 November 2011


Some rules have been added, the control panel has been shrunk and the code more clearly organized
The rules are between lines 392 and 869.

Canvas->Polygon Agents - Version 12 - AutoRun and FullScreen
3D (a work in progress) 29 March 2011


The control panel has been changed from "portrait" to "landscape" mode to fit smaller displays.
Features have been added to the PopUp Menu.
Two new rules have been added:
a) seek a random agent: image one, image two, image three, image four.
b) seek a consecutive agent: image one, image two, image three, image four.
These "look best" using a low population, moderate independence, color by speed and trail w/o black pen.
Nothing more has been done to the 3d functions. They are the same as they were in Version 11, that is to say
that under the "Radius" rule, agents calculate who they can see in 3D but only respond in 2D (they do not
move in the z-plane (in or out of the screen).

Canvas->Polygon Agents - Version 11 - AutoRun and FullScreen
3D (a work in progress)


Converting Version 10 to 3D is conceptually straightforward, but in practice, a bit more difficult.
(Much of the difficulty arises in coordinating user choices with functions and renderings.)
This 3D version is unfinished, but it does illustrate where we can go with the enhancement.
The depth of the world is set to the same as the height of the monitor.
The visualization of depth is foreshortened, because otherwise one's eyes have difficulty converging.
The agents do move in 3D. The agents perceive in 3D.
However, their directions and velocities are still only calculated in 2D. (This needs to be added.)
Also, the rules need to exclude 3D calculations when the visualization is not anaglyphic.
Rendering the agents needs to allow for a uniform size, or a size decreasing with depth.
A Pen->Width of 2 enhances the visualization, but slows computation considerably.
A Pen->Width of 3 creates artifacts on the screen.

 


Flocking Polygons by Matt Newcomb, Fall 2010

 


Flocking Polygons by Yang Su, Fall 2010

 

 


Flocking Polygons by Amy Peniston, Fall 2010

Canvas->Polygon Agents - Version 10 - Full Screen - Multiple Timers

This application automatically expands to the size of the display:
Form1->AutoSize = false;
Form1->BorderStyle = bsNone;
Form1->WindowsState = wsNormal; *
Form1 and PaintBox1 sizes are set to MonitorHeight and MonitorWidth.

Since the standard Windows controls do not appear:
Event handlers must be created to execute Form1->Close().
A PopUp Menu is used to show and hide the controls.

To make the application run with continuously varying parameters:
Nine timers control the positions of nine TrackBars.
The suspect population timer has been disabled.*

*wsMaximized appears to have caused the Access Violations in the previous version #9.

Canvas->Polygon Agents - Versions 7 & 8

Variable and function names have been made more intuitive. Coloring has been improved. Trails may be displayed without the Pen->Color = clBlack;. Agents may be colored by their speed, location or number of neighbors in their perceptual radius. TrackBars for Perceptual Radius, Independence and Variance. Rules include Nearest Neighbor, Weighted Neighbors within a Radius and Follow the Moving or Fixed Cursor. Left-click to "fix" or "unfix" the cursor position as the target.

Try this: Set color to speed; set rule to follow; set independence to high. Stir up the agents by leading them with a large circular motion of the mouse. Once the agents are in sync, quickly fix the cursor target in the center of the paintbox with a left-click. Now you can use the Mouse to adjust the other parameters.

Try this: Set color to speed; set rule to follow and fix the cursor target in the center. Slide independence trackbar to 0 until all agents are churning nicely at the center, then quickly slide it to maximum. Watch the oscillations which will become more subtle you press Reset.

Version 7 - Manually Controlled
(User sets all parameters)
Version 8 - Automatically Controlled
(Multiple timers set parameters)

Canvas->Polygon Agents - Version 5

The agents are represented as Canvas->Polygons pointing in the direction of travel and with sizes based upon their speed. Instead of velocities, agents are given the distance they travel per timestep in the X direction (dX) and in the Y direction (dY). Three options for coloring are included. Two functions for agent interaction are included. What functionality must you add to give the agents more realistic behavior?

Canvas->Rectangle Agents - Versions 2 and 3

Wandering squares is an attempt to add more power to the simulation, to make it run faster and with more agents. It takes many more computer cycles to move TImages around. In contrast, drawing squares on the canvas and erasing them is orders of magnitude faster. In fact, drawing a square is ten times faster than drawing circles. Additionally, instead of the velocities and directions given to agents in the "Flocking" series, which need to be reduced to their components with each time step, the "Wandering Squares" series simply uses the change in the x and y directions, dX and dY in the code, as the steps each agent will use per time step.

This is a demonstration version, which will run smoothly if you don't change the size of the squares. Feel free to add code to give agents more realistic behavior...

Version - 2 - 21 October 2009
2000 Canvas->Rectangle Agents in a 700 x 700 world.
Window size is 990 x 758 pixels.
This is the highest resolution for default settings.
Agents may be probed and colored.

Version - 3 (new and improved) - 26 October 2009
1000 Canvas->Rectangle Agents in a 900 x 900 world.
For a screen resolution of 1280 x 960.
This is the highest resolution that can be projected.
Agents may be thrown and slowed.

2000 Wandering Squares - Version 1

Wandering squares is an attempt to add more power to the simulation, to make it run faster and with more agents. It takes many more computer cycles to move TImages around. In contrast, drawing squares on the canvas and erasing them is orders of magnitude faster. In fact, drawing a square is ten times faster than drawing circles. Additionally, instead of the velocities and directions given to agents in the "Flocking" series, which need to be reduced to their components with each time step, the "Wandering Squares" series simply uses the change in the x and y directions, dX and dY in the code, as the steps each agent will use per time step.

Almost all the activity of this simulation has been written into the class structure. Also, in contrast to the flocking simulations below which use TImage or TShape objects, the agents in this simulation use Canvas draw commands. Interestingly, Canvas->Rectangle() executes about ten times faster than Canvas->Ellipse() which allows for a huge number of agent visualizations. This is not surprising since a circle is composed of many more line segments than a square.

Nicholas Mei's Flocking - 2008
An elaboration on flocking and schooling behavior with multiple controls and an aesthetic sensitivity. Developed independently from Michael Chang's Aquarius.

Michael Chang's Aquarius
An elaboration on flocking and schooling behavior with multiple controls and an aesthetic sensitivity.

Michael Chang's Evolva
Swimming creatures attract and avoid one another, feed on prey, are born, grow and die in a simulated ecosystem. Fully commented geometric functions to enable dynamic spatial movement are included under "Michael's Tools."

Michael Chang's Transitional Lines
Developed in C and imported into Director, points follow their targets, located in clusters on a rotating invisible ring surrounding the cursor. As the speed of the cursor increases, so does the radius of the ring and the warmth of the trails left by the points.

Bob and Carol and Ted and Alice
Bob likes Carol who likes Ted who likes Alice. Depending on their individual degrees of attraction, what paths will they take to get together?

Attraction & Avoidance
This application was inspired by a *Logo program written by Jeff Shih. Each one of 100 agents is randomly assigned two other agents: one to avoid and another to be attracted to. The strengths of the attraction and avoidance may be varied and visualized. Agents paths may also be tracked and visualized.