Skip to content

DefiningDisplaysGeneralities

mazarsju edited this page Jan 29, 2016 · 19 revisions

Defining displays (Generalities)

Index

Displays and layers

A display is the graphical output of your simulation. You can define several displays related with what you want to represent from your model execution. To define a display, use the keyword display inside the output scope, and specify a name (name facet).

experiment my_experiment type: gui {
	output {
		display "display1" {
		}
		display name:"display2" {
		}
	}
}

Other facets are available when defining your display:

  • Use background to define a color for your background
display "my_display" background:#red
  • Use refresh if you want to refresh the display when a condition is true (to refresh your display every number of steps, use the operator every)
display "my_display" refresh:every(10)

You can choose between two types of displays, by using the facet type:

  • java2D displays will be used when you want to have 2D visualization. It is used for example when you manipulate charts. This is the default value for the facet type.
  • opengl displays allows you to have 3D visualization.

You can save the display on the disk, as a png file, in the folder name_of_model/models/snapshots, by using the facet autosave. This facet takes one a boolean as argument (to allow or not to save each frame) or a point (to define the size of your image). By default, the resolution of the output image is 500x500.

display my_display autosave:true type:java2D {}

is equivalent to :

display my_display autosave:{500,500} type:java2D {}

Each display can be decomposed in one or several layers. Here is a screenshot (from the Toy Model Ant) to better understand those different notions we are about to tackle in this session.

images/difference_layer_display.png

Organize your layers

In one 2D display, you will have several types of layers, giving what you want to display in your model. Each layer will be displayed in the same order as you declare them. The last declared layer will be above the others.

Thus, the following code:

experiment expe type:gui {
	output {
		display my_display {
			graphics "layer1" {
				draw square(20) at:{10,10} color:#red;
			}
			graphics "layer2" {
				draw square(20) at:{15,15} color:#blue;
			}
			graphics "layer3" {
				draw square(20) at:{20,20} color:#yellow;
			}
		}
	}
}

Will have this output:

images/layers_order.png

You have a large number of layers available. You already know some of them, such as species, agents, grid, but other specific layers such as image (to display image), text (to display text) and graphics (to freely draw shapes/geometries/texts without having to define a species) are also available:

experiment expe type:gui {
	output {
		display display_an_image {
		   image "layer_name" file:"../images/my_image.png";
		}
		display display_a_text {
		   text "layer_name" value:"here your text";
		}
		display display_some_geometry {
			graphics "my_layer" {
				draw rectangle(2,5);
				draw text:"here a text";
			}
		}
	}
}

Most of the layers have the transparency facet in order to see the layers which are under.

experiment expe type:gui {
	output {
		display my_display {
			graphics "layer1" {
				draw square(20) at:{10,10} color:#red;
			}
			graphics "layer2" transparency:0.5 {
				draw square(20) at:{15,15} color:#blue;
			}
		}
	}
}

images/layers_transparency.png

To specify a position and a size for your layer, you can use the position and the size facets. The position facet is used with a point type, between {0,0} and {1,1}, which corresponds to the position of the upper left corner of your layer in percentage. Then, if you choose the point {0.5,0.5}, the upper left corner of your layer will be in the center of your display. By default, this value is {0,0}. The size facet is used with a point type, between {0,0} and {1,1} also. It corresponds to the size occupied by the layer in percentage. By default, this value is {1,1}.

images/layers_size_position.png

A lot of other facets are available for the different layers. Please read the documentation about this for more information.

Example of layers

agents layer

agents allows the modeler to display only the agents that fulfill a given condition.

display display_name {
   agents layer_name value: expression [additional options];
}

Additional options include:

  • value (type = container) the set of agents to display
  • aspect: the name of the aspect that should be used to display the species.
  • transparency (type = float, from 0 to 1): the transparency rate of the agents (1 means no transparancy)
  • position (type = point, from {1,1} to {0,0}): position of the upper-left corner of the layer (note that {0.5,0.5} refers to the middle of the display)
  • size (type = point, from {1,1} to {0,0}): size of the layer ({1,1} refers to the original size whereas {0.5,0.5} divides by 2 the height and the width of the layer)
  • refresh (type = boolean, opengl only): specify whether the display of the species is refreshed. (usefull in case of agents that do not move)
  • z (type = float, from 0 to 1, opengl only): altitude of the layer displaying agents
  • focus (type = agent)

For instance, in a segregation model, agents will only display happy agents:

display Segregation {
   agents agentDisappear value : people as list where (each.is_happy = false) aspect: with_group_color;
}

species layer

species allows modeler to display all the agent of a given species in the current display. In particular, modeler can choose the aspect used to display them.

The general syntax is:

display display_name {
   species species_name [additional options];
}

Additional options include:

  • aspect: the name of the aspect that should be used to display the species.
  • transparency (type = float, from 0 to 1): the transparency rate of the agents (1 means no transparancy)
  • position (type = point, from {1,1} to {0,0}): position of the upper-left corner of the layer (note that {0.5,0.5} refers to the middle of the display)
  • size (type = point, from {1,1} to {0,0}): size of the layer ({1,1} refers to the original size whereas {0.5,0.5} divides by 2 the height and the width of the layer)
  • refresh (type = boolean, opengl only): specify whether the display of the species is refreshed. (usefull in case of agents that do not move)
  • z (type = float, from 0 to 1, opengl only): altitude of the layer displaying agents

For instance it could be:

display my_display{
  species agent1 aspect: base ;
}

Species can be superposed on the same plan:

display my_display{
  species agent1 aspect: base;
  species agent2 aspect: base;
  species agent3 aspect: base;
}

Species can be placed on different z values for each layer using the opengl display. z:0 means the layer will be placed on the ground and z=1 means it will be placed at an height equal to the maximum size of the environment.

display my_display type: opengl{
  species agent1 aspect: base z:0;
  species agent2 aspect: base z:0.5;
  species agent3 aspect: base z:1;
}

image layer

image allows modeler to display an image (e.g. as background of a simulation). The general syntax is:

display display_name {
   image layer_name file: image_file [additional options];
}

Additional options include:

  • file (type = string): the name/path of the image (in the case of a raster image)
  • gis (type = string): the name/path of the shape file (to display a shapefile as background, without creating agents from it)
  • color (type = color): in the case of a shapefile, this the color used to fill in geometries of the shapefile
  • transparency (type = float, from 0 to 1): the transparency rate (1 means no transparancy)
  • position (type = point, from {1,1} to {0,0}): position of the upper-left corner of the layer (note that {0.5,0.5} refers to the middle of the display)
  • size (type = point, from {1,1} to {0,0}): size of the layer ({1,1} refers to the original size whereas {0.5,0.5} divides by 2 the height and the width of the layer)
  • refresh (type = boolean, opengl only): specify whether the display of the image is refreshed.
  • z (type = float, from 0 to 1, opengl only): altitude of the layer displaying the image

For instance:

display my_display{
  image background file:"../images/my_backgound.jpg";
}

Or

display city_display refresh_every: 1 {
   image testGIS gis: "../includes/building.shp" color: rgb('blue');
}

It is also possible to superpose images on different layers in the same way as for species using opengl display.

display my_display type:opengl{
  image image1 file:"../images/image1.jpg";
  image image2 file:"../images/image2.jpg" z:0.5;
}

text layer

text allows the modeler to display a string (that can change at each step) in a given position of the display. The general syntax is:

display my_display {
  text  my_text value: expression [additional options];

Additional options include:

  • value (type = string) the string to display
  • transparency (type = float, from 0 to 1): the transparency rate of the layer (1 means no transparancy)
  • position (type = point, from {1,1} to {0,0}): position of the upper-left corner of the layer (note that {0.5,0.5} refers to the middle of the display)
  • size (type = point, from {1,1} to {0,0}): size of the layer ({1,1} refers to the original size whereas {0.5,0.5} divides by 2 the height and the width of the layer)
  • font: the font used for the text
  • color (type = color): the color used to display the text
  • refresh (type = boolean, opengl only): specify whether the layer is refreshed.
  • z (type = float, from 0 to 1, opengl only): altitude of the layer displaying text

For instance:

display my_display {
   text agents value : 'Carrying ants : ' + string ( int ( ant as list count (each . has_food ) ) + int ( ant as list count ( each . state =    'followingRoad' ) ) ) position : { 0.5 , 0.03 } color : rgb ( 'black' ) size: { 1 , 0.02 };  
}

graphics layer

graphics allows the modeler to freely draw shapes/geometries/texts without having to define a species. The general syntax is:

display my_display {
  graphics "my new layer" {
    draw circle(5) at: {10,10} color: rgb("red");
    draw "test" at: {10,10} size: 20 color: rgb("black");
  }
  1. What's new (Changelog)
  1. Installation and Launching
    1. Installation
    2. Launching GAMA
    3. Updating GAMA
    4. Installing Plugins
  2. Workspace, Projects and Models
    1. Navigating in the Workspace
    2. Changing Workspace
    3. Importing Models
  3. Editing Models
    1. GAML Editor (Generalities)
    2. GAML Editor Tools
    3. Validation of Models
  4. Running Experiments
    1. Launching Experiments
    2. Experiments User interface
    3. Controls of experiments
    4. Parameters view
    5. Inspectors and monitors
    6. Displays
    7. Batch Specific UI
    8. Errors View
  5. Running Headless
    1. Headless Batch
    2. Headless Server
    3. Headless Legacy
  6. Preferences
  7. Troubleshooting
  1. Introduction
    1. Start with GAML
    2. Organization of a Model
    3. Basic programming concepts in GAML
  2. Manipulate basic Species
  3. Global Species
    1. Regular Species
    2. Defining Actions and Behaviors
    3. Interaction between Agents
    4. Attaching Skills
    5. Inheritance
  4. Defining Advanced Species
    1. Grid Species
    2. Graph Species
    3. Mirror Species
    4. Multi-Level Architecture
  5. Defining GUI Experiment
    1. Defining Parameters
    2. Defining Displays Generalities
    3. Defining 3D Displays
    4. Defining Charts
    5. Defining Monitors and Inspectors
    6. Defining Export files
    7. Defining User Interaction
  6. Exploring Models
    1. Run Several Simulations
    2. Batch Experiments
    3. Exploration Methods
  7. Optimizing Model Section
    1. Runtime Concepts
    2. Optimizing Models
  8. Multi-Paradigm Modeling
    1. Control Architecture
    2. Defining Differential Equations
  1. Manipulate OSM Data
  2. Diffusion
  3. Using Database
  4. Using FIPA ACL
  5. Using BDI with BEN
  6. Using Driving Skill
  7. Manipulate dates
  8. Manipulate lights
  9. Using comodel
  10. Save and restore Simulations
  11. Using network
  12. Headless mode
  13. Using Headless
  14. Writing Unit Tests
  15. Ensure model's reproducibility
  16. Going further with extensions
    1. Calling R
    2. Using Graphical Editor
    3. Using Git from GAMA
  1. Built-in Species
  2. Built-in Skills
  3. Built-in Architecture
  4. Statements
  5. Data Type
  6. File Type
  7. Expressions
    1. Literals
    2. Units and Constants
    3. Pseudo Variables
    4. Variables And Attributes
    5. Operators [A-A]
    6. Operators [B-C]
    7. Operators [D-H]
    8. Operators [I-M]
    9. Operators [N-R]
    10. Operators [S-Z]
  8. Exhaustive list of GAMA Keywords
  1. Installing the GIT version
  2. Developing Extensions
    1. Developing Plugins
    2. Developing Skills
    3. Developing Statements
    4. Developing Operators
    5. Developing Types
    6. Developing Species
    7. Developing Control Architectures
    8. Index of annotations
  3. Introduction to GAMA Java API
    1. Architecture of GAMA
    2. IScope
  4. Using GAMA flags
  5. Creating a release of GAMA
  6. Documentation generation

  1. Predator Prey
  2. Road Traffic
  3. 3D Tutorial
  4. Incremental Model
  5. Luneray's flu
  6. BDI Agents

  1. Team
  2. Projects using GAMA
  3. Scientific References
  4. Training Sessions

Resources

  1. Videos
  2. Conferences
  3. Code Examples
  4. Pedagogical materials
Clone this wiki locally