Skip to main content
Version: 🚧 Alpha 🚧

Defining displays (Generalities)

Displays and layers​

A display is one of the graphical outputs of a simulation. Define it inside the experiment's output block with an identifier after display; use the optional title: facet for the label shown in the interface. A graphical experiment is declared with mode: gui.

experiment my_experiment mode: gui {
output {
display display1 title: "display1" {
}
display display2 title: "Second display" {
}
}
}

Other facets are available when defining your display:

  • Use background to define a color for your background:
display my_display title: "my_display" background: #red
  • Use refresh to update the display only when a Boolean condition is true. For example, every(10#cycle) refreshes it every ten simulation cycles.
display my_display title: "my_display" refresh: every(10#cycle)
  • You can choose between 2D and 3D displays with the renderer facet:

    • 2d selects the 2D renderer. This is the default.
    • 3d selects the 3D renderer.

The autosave facet saves display images. true uses a 500 × 500 resolution and a generated filename; a point sets the resolution, and a string sets the filename while keeping the default resolution. If the filename is constant, a later image can overwrite the previous one. Enabling autosave: true synchronizes all displays in the experiment.

display my_display autosave: {1200, 800} renderer: 2d {}

The complete list of the display's facets are available in the documentation

Each display can be decomposed in one or several layers. Most of the time, all the layers are superimposed and cover all the environment space. In a 3D (OpenGL) display the layers can be split in order to be visualized separately (cf the page about displays).

Organize your layers​

In one 2D display, you will have several types of layers, giving what you want to display in your model. 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 picture (to display image backgrounds) and graphics (to freely draw shapes/geometries/texts without having to define a species) are also available

Each layer will be displayed in the same order as you declare them. The last declared layer will be above the others. As a consequence, any layer can hide elements of the lower levels.

Thus, the following code:

experiment expe mode: gui {
output {
display my_display {
graphics "layer1" {
draw square(20) at: {10,10} color: #gold;
}
graphics "layer2" {
draw square(20) at: {15,15} color: #darkorange;
}
graphics "layer3" {
draw square(20) at: {20,20} color: #cornflowerblue;
}
}
}
}

Will have this output:

Example of 3 layers in a display showing that the last one can hide the lower ones.

Most of the layers have a transparency facet that you can use in order to see the layers which are under.

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

Example of use of the transparency in a layer.

To specify a layer's position and size, use the position and size facets. Their meaning depends on the layer's coordinate mode: most layers, including graphics, default to #world, where values are model units. overlay and chart layers default to #screen; in this mode, values with magnitude below 1 are fractions of the viewport, while values from 1 are logical pixels. Set coordinates: #screen explicitly when a graphics layer should remain fixed to the viewport.

The position facet is a point at the layer's upper-left corner. In #screen coordinates, {0.5,0.5} places that corner halfway across and down the viewport; {0,0} is the top-left. Negative screen values count from the opposite edge. In #world coordinates, the point uses model units.

The size facet is a point describing the layer's extent. In #screen coordinates, {1,1} is one logical pixel by one logical pixel, not the full viewport. If omitted, the layer fills its reference extent. In #world coordinates, the point uses model units.

experiment expe mode:gui {
output {
display my_display {
graphics "layer1" coordinates: #screen position:{0,0} size:{0.5,0.8} {
draw shape color:#darkorange;
}
graphics "layer2" coordinates: #screen position:{0.3,0.1} size:{0.6,0.2} {
draw shape color:#cornflowerblue;
}
graphics "layer3" coordinates: #screen position:{0.4,0.2} size:{0.3,0.8} {
draw shape color:#gold;
}
}
}
}

Illustration of the use of the size and position facet of a layer.

NB: displays can have a background, while graphics can't. If you want to put a background for your graphics, a solution can be to draw the shape of the world (which is, by default, a square 100m*100m).

A lot of other facets are available for the various layers. Please read the documentation of graphics for more information.

Example of layers​

species layer​

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

Please read the documentation about species statement if you are interested.

grid layer​

grid displays the agents of a grid species. Its border facet sets the color of cell borders. The inner color of each cell is determined by the color built-in attribute of its grid agent. This is an optimized way to display grid agents compared with a species layer.

Please read the documentation about grid agents if you are interested.

agents layer​

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

Please read the documentation about agents statement if you are interested.

Picture layer​

picture allows the modeler to display an image (e.g. as the background of a simulation).

Please read the documentation about picture statement if you are interested.

graphics layer​

graphics allows the modeler to freely draw shapes/geometries/texts without having to define a species.

Please read the documentation about graphics statement if you are interested.