/
GAMA 1.8.gaml
215 lines (178 loc) · 4.49 KB
/
GAMA 1.8.gaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/***
* Name: GAMA 1.8 is out !
* Author: A. Drogoul
* Description: A toy model demonstrating "morphing" technologies in GAMA
* Tags: image, geometries
***/
model GAMA
global control: fsm {
rgb blue <- rgb(54, 112, 160);
rgb orange <- rgb(210, 103, 59);
rgb yellow <- rgb(238, 182, 79);
list<runner> runners <- list(runner);
shape_file town_file <- shape_file("../includes/buildings2.shp");
shape_file road_file <- shape_file("../includes/roads.shp");
geometry shape <- envelope(town_file);
float size <- shape.width / 100;
graph the_graph <- as_edge_graph(road_file.contents);
int distance_between (rgb c1, rgb c2) {
return abs(c1.red - c2.red) + abs(c1.green - c2.green) + abs(c1.blue - c2.blue);
}
rgb closest_color (rgb c1) {
int db <- distance_between(c1, blue);
int do <- distance_between(c1, orange);
int dy <- distance_between(c1, yellow);
int m <- min(db, do, dy);
if (m > 100) {
return #black;
} else if (m = db) {
return blue;
} else if (m = do) {
return orange;
} else if (m = dy) {
return yellow;
} }
action load_image (string the_path) {
matrix<int> colors <- (image_file(the_path).contents);
ask background {
color <- myself.closest_color(rgb(colors[grid_x, grid_y]));
}
map<rgb, list<background>> by_color <- background group_by (each.color);
ask runner {
target <- one_of(by_color at color);
}
runners <- list(runner);
}
action one_step {
ask runners {
do goto target: target speed: 2 * size / #s;
}
runners <- runners select (each.location != each.target.location);
}
init {
ask (list(background) every 16) {
create runner with: (location: location);
} }
state phase0 initial: true {
enter {
ask runner {
my_shape <- cube(rnd(size, size * 2));
depth <- rnd(size * 2);
}
}
ask runner {
my_shape <- cube(rnd(size, size * 2));
depth <- rnd(size * 2);
}
transition to: phase1 when: cycle = 10;
}
state phase1{
enter {
ask runner {
my_shape <- cube(rnd(size, size * 2));
depth <- rnd(size * 2);
}
do load_image("../includes/logo.png");
}
do one_step();
transition to: phase2 when: empty(runners);
}
state phase2 {
enter {
do load_image("../includes/version.png");
}
do one_step();
ask runner {
my_shape <- cube(rnd(size, size * 2));
depth <- rnd(size * 2);
}
transition to: phase3 when: empty(runners);
}
state phase3 {
enter {
do load_image("../includes/is_out.png");
}
do one_step();
ask runner {
my_shape <- box(rnd(size, size * 2), rnd(size, size * 2), rnd(size * 8));
depth <- rnd(size * 4);
}
transition to: phase4 when: empty(runners);
}
state phase4 {
enter {
ask (runner) {
if (flip(0.2)) {
do die;
}
}
ask (runner select (each.color = yellow)) {
create people with: (location: location);
do die;
}
ask (runner select (each.color = orange)) {
create roads with: (location: location);
do die;
}
ask runner {
target <- one_of(town_file.contents);
}
runners <- list(runner);
}
ask runners {
do goto target: target speed: 2 * size / #s;
if (location = target.location) {
my_shape <- target;
}
}
runners <- runners select (each.location != each.target.location);
}
}
grid background width: 297 height: 297;
species roads skills: [moving] {
geometry target <- one_of(road_file.contents);
geometry my_shape <- cube(rnd(size, size * 2));
reflex go when: target != nil {
do goto target: target speed: 2 * size / #s;
if (location = target.location) {
my_shape <- target + size / 8;
}
}
aspect default {
draw my_shape at: location color: orange;
}
}
species people skills: [moving] {
init{
target<-one_of(road_file.contents);
}
geometry target;
rgb color;
reflex move when:target != nil {
do goto on: the_graph target: target speed: 2 * size / #s;
if (location = target.location) {
target<-one_of(road_file.contents);
}
}
aspect default {
draw circle(size / 4) color: yellow at: location + {0, 0, size};
}
}
species runner skills: [moving] {
rgb color <- one_of(blue, orange, yellow);
geometry target;
geometry my_shape;
float depth;
}
experiment "Run me !" type: gui autorun: true {
output {
display "1.8" type: opengl fullscreen: true toolbar: #black background: #black draw_env: false
camera_location: {1298.0375, 3277.2938, 2177.5545} camera_target: {1261.3366, 1174.7007, 0.0} {
species roads;
species runner {
draw my_shape at: location depth: depth color: color;
}
species people;
}
}
}