- Art
- Astronomy
- Biology
- Selection and Mutation Series
- Ant Patterns
- Bacterial Growth
- Bark Beetles
- Biological Buffer
- Birds Competing For Worms
- Color Bunnies
- Ecosystem - Predator, Prey, and Grass
- Ecosystem - Rabbits and Grass
- Ecosystem - Two Species
- Ecosystem With Predator, Prey, And Grass
- Forest Fire
- Honeycomb Formation
- Termites Perimeter
- Yeast Growth
- Chemistry
- Earth Science
- Mathematics
- Physics
- Social Science
Ant Patterns
Submitted by librarian on Thu, 2006-08-03 13:55. :: Category
WHAT IS IT?
In this model, "ants" follow a very simple movement rule, which results in complex patterns. (The model's ants don't actually model real ant behavior - but some aspects of the resulting movement resemble the wandering of ants.)
HOW IT WORKS
At each step, each ant moves forward, and checks the color of the patch on which it stands. If the patch is black, the turtle stamps it with its own color (actually, a slightly lighter shade of that color) and turns right 90 degrees; otherwise, the turtle stamps the patch black and turns left 90 degrees.
The model also includes buttons which allow the user to add an ant to the model by clicking an empty patch on the canvas, and to remove an ant from the model by clicking on a patch with an ant.
HOW TO USE IT
Use the "Clear" button to reset the canvas, and remove any turtles.
The "Ant Color" slider is used to specify the basic color of the next ant added to the model. It ranges from zero (gray) to 13 (pink), in the same order as the standard StarLogo color spectrum. (The numeric color used for the ant will be 10 * slider + 2.)
The "Ant Heading" slider can be used to set the initial heading of the next ant added to the model, where 0 = North (0 degrees), 1 = East (90 degrees), 2 = South (180 degrees), and 3 = West (270 degrees).
Click the "Add Ants" button, and then click the canvas, to add an ant in the patch clicked on the canvas; the new ant will have the heading and color specified in the sliders. Because "Add Ants" remains down until it is pressed again, multiple ants can be added without having to press the button again and again; also, the slider values can be changed while "Add Ants" is down, so that each ant has a different color and/or heading.
To remove ants from the model, click "Remove Ants", and then click on an ant in the model. (Note that if the patch size is less than 8, ant shapes will not be used, and it can be difficult to see the ants, especially if the ant has stamped many patches. For this reason, the ant color is slightly darker than the color stamped on the patches, in order to provide some contrast.)
Click the "Go!" button to set the ants in motion.
THINGS TO NOTICE
At the start, when the canvas is sparsely filled, ants seem to alternate between slowly expanding a seemingly messy ball of color and shooting off at an angle with a ladder-like structure. When the canvas is more densely filled, the motion seems to have very little structure at all.
Two ants generally seem to move in such a way that they fill a portion of the canvas, and then backtrack over their paths, clearing the canvas and returning to the starting positions (or nearly so). Note that when this happens, the two ants seem to have traded places!
EXPLORATIONS
Test the above hypothesis, with different placement and heading combinations of two ants. Does the hypothesis hold?
Are there any general patterns of movement that you can identify when you start with three ants? With four ants?
THINGS TO TRY
Start by adding a single ant, and clicking "Go!". Notice the wild motion of the ant - which seems to grow more chaotic and random as time goes on.
Click the "Clear" button, and start again. This time, create two ants - with contrasting colors, but the same heading. Does the pattern created by the two ants seem more or less chaotic than the pattern created by a single ant?
EXTENDING THE MODEL
Conceivably, the model could be extended to support arbitrary initial headings for the ants, and/or different turn angles in the basic rules. However, one of the most interesting things about this model is that such simple rules give rise to such complexity.
STARLOGO FEATURES
The model uses the "mouse-down?", "mouse-xcor", and "mouse-ycor" commands to add and remove ants from the model. Because mouse clicks outside the canvas will be interpreted as clicks on the outermost rows or columns of patches, the latter are ignored along with the former.
CREDITS AND REFERENCES
This model is based on the ant_patterns model included original StarLogo models library. The current version was executed by Nick Bennett in March 2006. The basic behavior of the model is unchanged, except for the addition of support for adding and removing ants by using the mouse to click patches on the canvas.
Turtle procedures
;; Procedure: initialize-ant
;; Called by: add-ant procedure (observer)
;;
;; Initialize a turtle with the specified attributes, and the termite shape.
;;
to initialize-ant :x :y :color :heading
setshape termite-shape
setxy :x :y
setcolor :color
setheading :heading
end
;; Procedure: go
;; Called by: Go button
;;
;; Move forward, and check the patch color. If it is black, stamp it with the
;; turtle's color and turn right; otherwise, stamp it black and turn left.
;;
to go
forward 1
ifelse (pc = black) [
stamp (color + 3)
right 90
] [
stamp black
left 90
]
end
Observer procedures
;; Procedure: Setup
;; Called by: Clear button
;;
;; Clears canvas & kills turtles.
to setup
clear-all
end
;; Procedure: add-ant
;; Called by: Add Ants button
;;
;; Wait until a mouse click is detected, and test whether it occurred in the
;; interior of the canvas. If so, and if there are no turtles already in the
;; patch clicked, create one with the specified color and heading.
;;
to add-ant
wait-until [mouse-down?]
let [:x mouse-xcor]
let [:y mouse-ycor]
if (((abs :x) < screen-half-width)
and ((abs :y) < screen-half-height)
and ((count-turtles-at :x :y) = 0)) [
create-turtles-and-do 1 [
initialize-ant :x :y (2 + ant-color * 10) (ant-heading * 90)
]
]
end
;; Procedure: remove-ant
;; Called by: Remove Ants button
;;
;; Wait until a mouse click is detected, and test whether it occurred in the
;; interior of the canvas. If so, and if there is a turtle in the patch
;; clicked, kill one of the turtles there.
;;
to remove-ant
wait-until [mouse-down?]
let [:x mouse-xcor]
let [:y mouse-ycor]
if (((abs :x) < screen-half-width)
and ((abs :y) < screen-half-height)
and ((count-turtles-at :x :y) > 0)) [
kill one-of-turtles-at :x :y
]
end
5749 reads
