[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.

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...

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 dis-enabled.*

*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 simualation 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.