Simulation with AnyLogic/Agent-Based Modeling/Step 10. Adding agent animations
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.
- Open the Person class diagram by double-clicking the Person item in the Project view.
- Zoom the diagram in, say to 400% scale.
- Drag the diagram a little bit down and to the right with the right mouse button pressed.
- Draw the agent shape like shown in the following figure:
- Draw it using a curve. Therefore, choose the Curve 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.
- 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):
- Zoom the diagram out.
- Click on the agent shape and open the Dynamic properties of the shape. In the Fill Color property, type
statechart.isStateActive(PotentialAdopter) ? royalBlue : red
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.
- Open the Main class diagram by double-clicking the Main item in the Project view.
- 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.
- Drag this shape down to the place shown in the following figure:
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.
- Select the environment object.
- 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.
We have finished creating the animation. Run the model and watch the dynamics on the network.