2. Vegetation dynamics
This step introduces a 50 Γ 50 vegetation grid. Each cell stores its food level and regrows food each cycle. Every prey is assigned to a cell and displayed at that cell's location.
Define the vegetation gridβ
The grid uses a four-cell neighborhood. food increases by food_prod up to max_food; the cell color is recalculated from its food level.
grid vegetation_cell width: 50 height: 50 neighbors: 4 {
float max_food <- 1.0;
float food_prod <- rnd(0.01);
float food <- rnd(1.0) max: max_food update: food + food_prod;
rgb color <- rgb(int(255 * (1 - food)), 255, int(255 * (1 - food))) update: rgb(int(255 * (1 - food)), 255, int(255 * (1 - food)));
}
Place prey on grid cellsβ
Each prey stores one selected cell in my_cell. Its init block places it at the cell's location.
species prey {
float size <- 1.0;
rgb color <- #blue;
vegetation_cell my_cell <- one_of(vegetation_cell);
init {
location <- my_cell.location;
}
aspect base {
draw circle(size) color: color;
}
}
Display the grid and preyβ
The display draws the vegetation cells first, then prey agents above them.
experiment prey_predator mode: gui {
parameter "Initial number of preys: " var: nb_preys_init min: 1 max: 1000 category: "Prey";
output {
display main_display map_order: true {
grid vegetation_cell border: #black;
species prey aspect: base;
}
}
}
For the complete PredatorβPrey model 2, see the GAMA model library.