«prev1 2 3 4next»

2. Defining the environment

The simulation environment is defined by:

At least initially, all of these are created using PNG images.

Backgronud and wall maps

The background image is displayed as the "ground" where things happen. It's purely cosmetic and has no influence in the simulation. The walls iamge, however, defines the places where agents can walk, and the places where they can't (walls). For the simulation to make visual sense, the walls and the background should match.

In Testland, we create a background image using some of gimp's tools to draw a labyrinth. Feel free to put in your own design here. Another idea is a snapshot from googlemaps or a floor plan. Once you're done, save it as background.png. This is now the base for your simulation. All the rest of images created in this tutorial must have the same dimensions.

Later on, in the next steps, you will need to calibrate this map, by providing the coordinates of its corners. If you captured the image from something like an on-line map, keep those points!.

Next you need to define what parts of that background image are walkable. Create a new image, based on the background, which is black on the walkable areas, and white on the walls, and save it as walls.png. Most of the time it pays to use the magic wand to select a certain color on the background, create a new layer, and paint it black; then paint the background layer white. At any rate, check the expected result.

Defining places

You can define places in the WorldModel on the next step, but calculating the coordinates of those places can be a pain. To make your life easier, you can define the places using images.

Sometimes you want to define multiple places like, say, homes, offices, bus stops, and you don't necessarily care which is which, because you want each of your agents to live in a random house, doesn't matter which one, so we have places, and types of places. Now, for each type of place, create a white image, and put a single black pixel for each place of that type.

Testland is a bit of an abstract world so, instead of houses and offices, we define only two types: "Nowhere" places and "Isolated" places. The first type includes two places in the main map area, and the second, two places in the isolated south east corner. The images end up looking like this: Nowhere.png and Isolated.png; look close, there are some dots in there!

Again, remember you can also define places at simulation runtime. In fact, a new place is created everytime you manually tell an agent where to go!

Defining environment context variables

Context variables can either be contained in the Agent itself (using the set and get methods), or can be linked to the map positions. The latter are called overlays, and would define, for instance the temperature, the hotspot range or the noise level at each position in the map. In the ContextModel (see the next step), you can modify this value matrix at will. In order to initialize it, however, we use images.

The value of a context variable is extracted from the pixel value at that point in the map. The translation is done according to the simulation config file, and can be one of three types:

So, there you go. For each overlay, you'll have to create an image per overlay. Grayscale images are highly recommended, because the lightness of a pixel is proportional to the pixel value. In testland, we create overlays of all three types, which we will calibrate when packing the simulation. Here are the images:

Naturally, if you happen to have image maps of your context variables, do use them to generate the overlays.


Latest code


Creating your own simulation