class TurtlesModel extends Model {
createSite(x, y, site_type) {
this.turtles.create(1, (t) => {
t.size = 1.0
t.speed = 0.0
t.x = x;
t.y = y;
t.properties = {}
t.properties.type = "site"
t.properties.siteType
t.properties.viral_load = 0.0
})
}
setup () {
this.turtles.own('speed')
this.turtles.setDefault('atEdge', 'wrap')
this.turtles.setDefault('z', 0.1)
this.turtles.create(numInfectedInitial, (t) => {
t.size = 0.3
t.speed = util.randomFloat2(0.03, 0.05)
t.properties = {}
t.properties.type = "person"
t.properties.viral_load = initial_viral_load
})
this.turtles.create(numPeople - numInfectedInitial, (t) => {
t.size = 0.3
t.speed = util.randomFloat2(0.03, 0.05)
t.properties = {}
t.properties.type = "person"
t.properties.viral_load = 0.0
})
// Suburb towns
const num_towns = 5;
const houses_per_town = 5;
const stores_per_town = 3;
const town_houses_radius = 2;
const town_store_radius = 1;
// Inner city
const city_center_x = 0;
const city_center_y = 0;
const num_office_buildings = 5;
const num_stores_inner_city = 12;
const office_buildings_radius = 2;
const city_store_radius = 4;
const outer_city_radius = 10;
var theta_which_town = 0;
var theta_within_town = 0;
for (var i = 0; i < num_towns; ++i) {
theta_which_town += 2 * Math.PI / num_towns;
const town_center_x = city_center_x + outer_city_radius * Math.cos(theta_which_town);
const town_center_y = city_center_y + outer_city_radius * Math.sin(theta_which_town);
this.createSite(town_center_x, town_center_y, "town_center");
for (var j = 0; j < houses_per_town; ++j) {
theta_within_town += 2 * Math.PI / houses_per_town;
const house_location_x = town_center_x + town_houses_radius * Math.cos(theta_within_town);
const house_location_y = town_center_y + town_houses_radius * Math.sin(theta_within_town);
this.createSite(house_location_x, house_location_y, "house");
}
for (var j = 0; j < stores_per_town; ++j) {
theta_within_town += 2 * Math.PI / stores_per_town;
const store_location_x = town_center_x + town_store_radius * Math.cos(theta_within_town);
const store_location_y = town_center_y + town_store_radius * Math.sin(theta_within_town);
this.createSite(store_location_x, store_location_y, "store");
}
}
// Create stores in city
var theta_inner_city = 0;
for (var i = 0; i < num_stores_inner_city; ++i) {
theta_inner_city += 2 * Math.PI / num_stores_inner_city;
const store_location_x = city_center_x + city_store_radius * Math.cos(theta_inner_city);
const store_location_y = city_center_y + city_store_radius * Math.sin(theta_inner_city);
this.createSite(store_location_x, store_location_y, "store");
}
// Create office buildings in city
for (var i = 0; i < num_office_buildings; ++i) {
theta_inner_city += 2 * Math.PI / num_office_buildings;
const building_location_x = city_center_x + office_buildings_radius * Math.cos(theta_inner_city);
const building_location_y = city_center_y + office_buildings_radius * Math.sin(theta_inner_city);
this.createSite(building_location_x, building_location_y, "office");
}
}
step () {
this.turtles.ask((t) => {
t.theta += util.randomCentered(0.1)
t.forward(t.speed)
t.properties.color = virus_color(t.properties.viral_load)
})
}
}