Agent Animation NetLogo Model

Produced for the book series "Exercises for Artificial Intelligence";

Author: W. J. Teahan; Publisher: Ventus Publishing Aps, Denmark.

powered by NetLogo

view/download model file: Agent-Animation.nlogo


This model performs a simple animation of various turtle agent shapes to give the impression that they are flowing past the observer. The user can select the size and shape of the agent, its position on the y-axis, the random interval at which the next agent will appear and the minimum gap between agents.


The purpose of this model is show how a simple translation movement can be used to perform basic animation of turtle agents.

This model illustrates a solution to Exercise 4.5.5 for the book "Exercises for Artificial Intelligence - Agents and Environments".


Turtle agents are created at random intervals on the left side of the environment. These are then moved horizontally across the environment by incrementing their x co-ordinate.


To run the animation, press the setup button followed by the animate-agents button. Changing the values of the chooser and sliders in the Interface during the animation will change the nature and frequency of the agents that appear in the animation.


The model's Interface buttons are defined as follows:

- setup: This resets the animation and draws the background.

- animate-agents: This starts the animation in the environment.

The model's Interface chooser and sliders are defined as follows:

- type-of-agent: This chooser selects the shape of the agent that appears next.

- size-of-agent: This is the size of the agent that appears next.

- next-agent-random-tick-interval: This controls how often the agents appear. The next agent will appear at an interval after the previous agent which is a random number from 0 up to this number + the value of the minimum-gap slider.

- minimum-gap: This is the minimum gap with which the agents appear.

- y-position: This is the y position of the agent which remains unchanged as the agent is moved across from left to right.


Notice which of the shapes (as defined by the type-of-agent chooser) seem to create realistic animation and which do not. The animation of the person, cow, mouse and sheep agents, for example, seem strange, and look like they are moving on a conveyor belt. Why?


Try changing the values of the chooser and sliders as the animation is running.

Try setting the value of the next-agent-random-tick-interval slider to 0 and the value of the minimum-gap slider to 1.


Try making the motorway animation more realistic i.e. when the type-of-agent chooser is set to "any of the motorway vehicles below". You will need to vary the size of some of the vehicle agents so that they end up similar sizes (for example, the "car" shape is too big in comparison to the other shapes). You will also need to vary the y positions of the different vehicle agents.

Try modifying the railway animation so that longer trains of agents appear rather than a single agent one at a time.


See the Cars Guessing Game model, and the Stick Figure Walking and Stick Figure Animation models.


This model was created by William John Teahan.

To refer to this model in publications, please use:

Teahan, W. J. (2010). Agent Animation NetLogo model.
Exercisaes for Artificial Intelligence. Ventus Publishing Aps.


; Animate Agents model.
; This provides a simple animation of agents moving from left to right.
; Copyright 2010 William John Teahan. All Rights Reserved.

breed [agents agent] ;; represents the agents that are going past the observer

  next-agent-tick      ;; when the next agent will appear
to setup
  ca ;; clear everything
  ask patches with [ pycor > -9 ] [ set pcolor 88 ] ; make everything light blue for the "sky"
  ask patches with [ pycor = -9 ] [ set pcolor 3 ]
  ask patches with [ pycor < -9 ] [ set pcolor 4 ] ; draw the road surface
  set next-agent-tick 0

to create-new-agent
;; creates a new car that enters screen from the left and
;; reports its colour
  let this-colour black
  create-agents 1
    ifelse (not member? type-of-agent ["any of the below" "any of the motorway vehicles below" "any of the railway vehicles below"])
      [ set shape type-of-agent ]
        if (type-of-agent = "any of the below")
          [ set shape one-of
              [ "airplane" "ambulance" "bike" "bus" "boat" "car" "car 2" "cow" "fish" "mouse" "person" "sailboat" "shark"
                "sheep" "train" "train freight engine" "train passenger car" "train passenger engine" "truck" "van" ]
        if (type-of-agent = "any of the motorway vehicles below")
          [ set shape one-of
              [ "ambulance" "bus" "car" "car 2" "truck" "van" ]            
        if (type-of-agent = "any of the railway vehicles below")
          [ set shape one-of
              [ "train" "train freight engine" "train passenger car" "train passenger engine" ]

    set heading 90
    set size size-of-agent
    set xcor (- max-pxcor)
    set ycor y-position

to animate-agents
; move the agents across the screen from left to right
  let colour black

  if (ticks = next-agent-tick)
      set next-agent-tick ticks + random next-agent-random-tick-interval + minimum-gap ; make sure cars are apart
  ask agents
  [ if (xcor + 1 > max-pxcor)
      [ die ] ; move this car off the screen
    set xcor xcor + 1 ; move this car to the right by 1
; Copyright 2010 by William John Teahan.  All rights reserved.
; Permission to use, modify or redistribute this model is hereby granted,
; provided that both of the following requirements are followed:
; a) this copyright notice is included.
; b) this model will not be redistributed for profit without permission
;    from William John Teahan.
; Contact William John Teahan for appropriate licenses for redistribution for
; profit.
; To refer to this model in publications, please use:
; Teahan, W. J. (2010).  Animate Agents NetLogo model.
;   Artificial Intelligence. Ventus Publishing Aps.