|
Flocking
- Borland C++ Builder 6 Applications
Do not assume that all code blocks in any one application are entirely
compatible with the code in other applications.
Please verify the compatibility yourself before you cut-and-paste.
|
|
|
Flocking 15: Revised June 1, 2008
The direction interactions have been corrected to
simulate more realistic interactions and to eliminate directional bias.
A new agent variable has been added called "seeking" which is
randomly filled with the identities of the other agents. In Rule #5, the
agent's direction is modified by the direction to the agent-being-sought.
Two variations are illustrated below. In these examples, "seeking"
has been assigned randomly. If "seeking" is assigned non-randomly
(e.g. hierarchically) and appropriate changes are made to the behavior,
more complex networks of intereactions may be developed.
|
|
|
|
|
Flocking 14: Revised May 26, 2008
Five agent types are now automatically created (Cyan,
Magenta, Yellow, White & Black). Three more agent types are available
(Red, Green & Blue) but are not implemented. The agent->type is
shown in the probe on MouseMove.
|
|
|
Flocking 13: Revised May 23, 2008
The couple's behaviors have been made reciprocal.
Each agent now remembers each of their encounters with all the other agents
during the couple's behaviors. MouseMove will display all encounters of
an individual agent with every other agent. A new button provides a visual
display of every agent's encounters with every other agent.
|
|
|
Flocking 12: Revised May 19, 2008
The default representation of space has been changed
to a toroidal (wrapped) world and all the neighbor functions reflect that
representation. An "add agent" feature has been added and the
simulation will accommodate 100 agents. Sounds have been added to many
user commands and to the "couples" behaviors. The "Corner"
button moves the selected Shapes and Images to the upper-left corner but
does not effect the positions of the agents.
|
|
|
Flocking 11: Revised and Simplified
Retains all the functionality of the previous versions.
The code has been cleaned up. The colorRamp()
function has been revised. Agents' paths (trails) are recorded.
Shapes are ready to display any agent information. To speed up the simulation,
movement of the images and/or the shapes may be turned off.
|
Flocking 11
xxxxx
Agents' paths colored by iteration.xxxxx
Agents' paths colored by tag (id).
With the rule set to "decrement
direction by that of your nearest neighbor," the time increment
set to minimum
and run to 5,000 iterations in wrap-around (toroidal) space.
Click on either image above for an inverted image run to 50,000 iterations.
|
|
|
Flocking 10: With Throwable Agents
All movement is controlled by the Nearest Neighbor
except for the "Average within Radius" rule where the radius
is set by the TrackBar. In this version, code has been added to capture
the time and coordinates distance between MouseDowns and MouseUps on the
agents' images allowing the user to "hurl" agents to give them
new directions and speeds. The Now(
) function returns the system time...
|
|
|
Flocking 9: + Average within a Radius
Rule
A new behavior is added as option 10. Given the Neighborhood
Radius selected by the TrackBar, the velocities and directions of all
agents within that radius are averaged and become those of the agent.
When no longer in a flock, an agent takes on a random velocity and direction.
Details are critically important and seemingly minor programming changes
can result in discernably different behaviors...
|
|
|
Flocking 8: + Gender Rule, + Bitmap
We have the ability to import a 612 by 612 bitmap
image from PhotoShop to use as a geographical environment for the agents.
Agents now have access to the three independent channels of data (the
red, green and blue layers). The Voyager agents have solid colored bodies
rather than transparent bodies as in the last version.
|
|
|
Flocking: + Gendered Agents &
Rules
An extension of using images to visualize a problem.
Images are taken from the NASA Voyager plaque and DaVinci. Agents are
distinguished as male or female and two new behaviors have been added
taking advantage of those differences. One behavior has same sex individuals
avoiding while opposite sex individuals follow one another. The next behavior
reverses the behaviors. See the source code for details of the rules.
Of course, much more can be done...
|
|
|
Flocking Snowflakes Sonified
Many things you can do with a TShape object you can
do with a TImage object. This version is identical to the last with the
exception that a transparent bitmap of a snowflake has been imported (bottom
right) and the dynamically created array of TImages have copied their
Picture properties from that image's Picture property. Only minor modifications
of the code were required to do this although there were a lot of them
to be made.
|
|
|
Rafael's Collision Avoidance
A physically accurate simulation of pedestrian collision
avoidance while travelling between points A and B.
|
|
|
Rafael's Vector / Vector Flocking
A physically accurate simulation of collisions with
and without gravitational attraction as well as other influences on neighboring
agents.
|
|
|
Coordinated
Arrays of Texts, Shapes and Images
You can use COORDINATED arrays of text, shape and
image components to build up complex visualizations for agents in a simulation.
In this sampler, picture properties of the images
may be changed dynamically by right-clicking. The shape colors may be
changed dynamically as well as the sizes of the images and shapes.
The faces Zipped,
if you want to use them elsewhere.
|
|
|
Traffic Flow
An emergent property of freeway traffic is the wave
of congestion which moves more slowly than the average speed of the vehicles.
From the perspective of the driver, the wave of traffic congestion moves
backwards: she sees it up ahead, whe is in it, then it passes behind.
The root cause of this wave is the reaction delay of the driver.
|
 |
Flocking Balls with Walls
We have introduced code to detect collisions with
walls and take the appropriate "bounce" or "wrap"
actions...
|
 |
Flocking Behaviors Sonified
Drag and Drop with the left mouse button.
Show the nearest neighbor with right mouse button.
Expect WINDOWS to
shut you down if you use the next-to-last rule - or - stop the simultion
before it gets out of hand. The "wrap"
(toroidal)
world is fairly peaceful, but expect some chaotic behavior in the "bounce"
(non-toroidal) world.
|
 |
Flocking - Sonified
Each wall may emit a different sound when hit:
Beep() plays the notes G, C, E & G.
PlaySound() WINDOWS plays Windows sounds.
PlaySound() Pinball plays Pinball sounds.
Midi plays the harpsicord notes G, C, E and G.
You could have the sound indicate
the agent number, speed, direction, collisions, etc.
|
|
|
Flocking - 2006
A foundation for a flocking simulation which consists
of 24 shape objects tied with 24 agents. Agents, in this application,
are blind - you will have to add your own sensors (neighborhoods). Agents
have directions, velocities, diameters, outline and fill colors. Assimilation
and/or approach and avoidance behaviors could be programed for each...
An array of image objects could replace the array of shape objects...
|
|
|
Arrays of Labels, Shapes and Images
Use arrays of Borland components to represent the
state of the agents in a simulation. In this sampler, we create an array
of TStaticText labels, an array of TShape shapes and an array of TImage
images. We also create event handlers for the images and code them to
enable drag-and-drop as well as changes in the ->Picture properties
of each. In this sampler, the labels, shapes and images are independent,
but they could be coordinated if desired. The images are transparent .bmp
bitmaps. The images could be colored if desired.
The faces Zipped,
if you want to use them elsewhere.
|
|
|
Ball and Kitten
Two transparent bitmap images are created, for a ball
and a kitten. Mouse Down, Move and Up events allow the user to drag and
rop either object. The kitten is periodically attracted to or repulsed
by the ball. When the kitten goes out of bounds it approaches the ball.
The greater the distance between the objects the greater the speed. However,
the programmer may wish to change this and other parameters.
|
|
|
Canvas Agents with Spatial Properties
Canvas graphics are ephemeral, meaning that they can
be erased with a Refresh() call (the "Clear" button) or obliterated
when another Window obscures them momentarily. The green/magenta figure
is drawn when "Draw" is pressed. The blue/cyan figure is drawn
when "FormPaint" is fired. The small figures are drawn by pressing
the run/step/stop/initialize buttons. The order in which functions are
declared, described and called is illustrated.
|
|
|
Traffic
Using an array of shape objects, this application
provides each agent with a velocity and a direction of movement. Trigonometric
functions (sine, cosine) and the Pythagorean Theorum are used to calculate
the dynamics. In the current implementation, the "balls" may
be "Reset" to random positions, velocities and directions and
may be forced into a "Circle" pattern. The "balls"
bounce off of the walls of the Window. The "Circulate" code
does not work in its current state and has been commented out.
|
|
|
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.
|
|
|
Growth by Diffusion Limited Aggregation
- Enhanced Version
Agents introduced from the edge of the world wander,
one at a time at random, until they meet a stationary agent. In this case,
that seed agent was placed in the center. The self-similar fractal pattern
shows the aggregation of 62,691 agents. The order of aggregation is represented
by a color gradient. The path of each wandering agent may be hidden or
shown in either white or along an additional color gradient. Re-rendering
the display will obliterate the color pattern. See Garry William Flake's
COMPUTATIONAL BEAUTY OF NATURE, figure 5.10, pages 74 and 75.
|