Simulation with AnyLogic/Agent-Based Modeling/Step 10. Adding agent animations

From Wikibooks, open books for an open world
< Simulation with AnyLogic‎ | Agent-Based Modeling
Jump to: navigation, search

Step 10. Adding Agent Animations

Now we will create a simple animation of our model to visualize the process. We want to draw agents on our presentation. Agents will be displayed relative to the coordinates they have in the modeled environment.Product adopters and potential adopters will be shown with the shapes of different colors.

Step 1. Creating a new model1.gif Draw a shape depicting a person

  1. Open the Person class diagram by double-clicking the Person item in the Project view.
  2. Zoom the diagram in, say to 400% scale.
    Step 10. Adding agent animations1.png
  3. Drag the diagram a little bit down and to the right with the right mouse button pressed.
  4. Draw the agent shape like shown in the following figure:
    Step 10. Adding agent animations2.png
  5. Draw it using a curve. Therefore, choose the Curve Step 10. Adding agent animations3.gif element from the Presentation stencil of the Palette view (this stencil contains shapes and controls you can add on your presentation) and successively click at each curve point on the diagram and finally double-click to finish drawing.
  6. Place the shape right in the upper left corner in the point (0,0) (the coordinates of the mouse cursor are shown in the status bar):
    Step 10. Adding agent animations4.png
  7. Zoom the diagram out.
  8. Click on the agent shape and open the Dynamic properties of the shape. In the Fill Color property, type
    statechart.isStateActive(PotentialAdopter) ? royalBlue : red
    Step 10. Adding agent animations5.png
    The expression checks, whether the person is a potential adopter (the PotentialAdopter state of the agent's statechart is active). Adopters will be displayed with red points, potential adopters – with blue ones.

Step 1. Creating a new model1.gif Modify the model to set up agent animations properly

  1. Open the Main class diagram by double-clicking the Main item in the Project view.
  2. Select the people object in the graphical editor. On the General page of its Properties view, click the Create Presentation button. You will see the agent shape appeared in the upper left corner.
  3. Drag this shape down to the place shown in the following figure:
    Step 10. Adding agent animations6.png
    The point where we place our shape will be the upper left corner of the agent's environment area. Agents with (0,0) coordinates will be placed there.
  4. Select the environment object.
  5. Open the Advanced' tab of the environments Properties view. Define the dimensions of the space our agents populate. Set up Width 650 and Height 300.
    Step 10. Adding agent animations7.png

We have finished creating the animation. Run the model and watch the dynamics on the network.

Step 10. Adding agent animations8.png