cacatoo
Version:
Building, exploring, and sharing spatially structured models
229 lines (184 loc) • 13.6 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cacatoo manual</title><link rel="icon" type="image/png" href="images/favicon.png" />
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/menu.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link href='https://fonts.googleapis.com/icon?family=Material+Icons' rel='stylesheet'>
<script src="scripts/jquery.js"></script>
<script src="scripts/cacatoo.js"></script> <!-- Include cacatoo library (compiled with rollup) -->
<script src="scripts/all.js"></script> <!-- Include other libraries (concattenated in 1 file) -->
<script>
/*-----------------------Start user-defined code ---------------------*/
let sim; // Declare a variable named "sim" globally, so that we can access our cacatoo-simulation from wherever we need.
/**
* function cacatoo() contains all the user-defined parts of a cacatoo-model. Configuration, update rules, what is displayed or plotted, etc. It's all here.
*/
function cacatoo() {
/*
1. SETUP. First, set up a configuration-object. Here we define how large the grid is, how long will it run, what colours will the critters be, etc.
*/
let config =
{
title: "Colony", // The name of your cacatoo-simulation
description: "", // And a description if you wish
maxtime: 1000000, // How many time steps the model continues to run
ncol: 200, // Number of columns (width of your grid)
nrow: 200, // Number of rows (height of your grid)
seed: 15,
wrap: [false, false], // Wrapped boundary conditions? [COLS, ROWS]
scale: 2, // Scale of the grid (nxn pixels per grid point)
statecolours: {'species': { 'low uptake': "#DDDDDD", // Sets up colours of states (here 1,2,3 = A,B,C). Can be a colour name or a hexadecimal colour.
'medium uptake': "red", // If your state it not defined, it won't be drawn and you'll see the grid-background colour (default: black)
'high uptake': "#3030ff"}}
}
/*
1. SETUP. (continued) Now, let's use that configuration-object to generate a new Cacatoo simulation
*/
sim = new Simulation(config) // Initialise the Cacatoo simulation
sim.makeGridmodel("growth") // Build a new Gridmodel within the simulation called "model"
sim.initialGrid(sim.growth,'external_resources',1000.0,1.0) // Give 100% of grid points external resources (set to 1)
let species = [{species:'low uptake',uptake_rate:5.0,internal_resources:1},
{species:'medium uptake',uptake_rate:10.0,internal_resources:1},
{species:'high uptake',uptake_rate:15.0,internal_resources:1}]
sim.populateSpot(sim.growth, species, [0.34,0.33,0.33], 100, config.ncol/2, config.nrow/2) // Place the three 'species' in a small spot in the middle of the grid
//sim.populateGrid(sim.growth, species, [0.001,0.001,0.001]) // Alternatively, innoculate the entire grid with species
sim.createDisplay("growth", "species", "Species") // Create a display in the same way we did in Tutorial 1 (display a discrete variable)
sim.createDisplay_continuous({model:"growth", property:"external_resources", label:"External resources", // Createa a display for a continuous variable (ODE state for external resources)
minval:0, maxval:1000, fill:"viridis"})
sim.createDisplay_continuous({model:"growth", property:"internal_resources", label:"Internal resources", // Createa a display for a continuous variable (ODE state for external resources)
minval:0, maxval:1000, fill:"viridis"})
/*
2. DEFINING THE RULES. Below, the user defines the nextState function. This function will be applied for each grid point when we will update the grid later.
*/
sim.growth.nextState = function (i, j) {
let randomneigh = this.randomMoore8(this, i, j) // Random neighbour
let this_gp = this.grid[i][j] // This cell
if (!this_gp.species) // If empty spot
{
if (randomneigh.species && randomneigh.internal_resources > 50) { // Random neighbour is alive and it has enough resources
this_gp.species = randomneigh.species // Empty spot becomes the parent type (reproduction)
this_gp.uptake_rate = randomneigh.uptake_rate // Empty spot inherits uptake rate from the parent
randomneigh.internal_resources = this_gp.internal_resources = randomneigh.internal_resources / 2 // Resources are divided between parent and offpsring
}
}
else {
if (this.rng.genrand_real1() < 0.01) { // Random death
this_gp.species = 0
this_gp.uptake_rate=0.0
this_gp.internal_resources = 0
}
else{
let uptake = this_gp.external_resources * (this_gp.uptake_rate/100) // Living cells can take up a fraction of available resources
this_gp.internal_resources += uptake
this_gp.external_resources -= uptake
this_gp.internal_resources *= 0.9
}
}
}
/*
3. MAIN SIMULATION LOOP. Finally, we need to set the update-function, which is the mainwill be applied to the whole grid each time step. For now, all we will do is call "synchronous", which
applies the next-state function shown above to each grid point. All cells are updated at the same time, rather than in turn (for this, use the function "asynchonous")
*/
sim.growth.update = function () {
this.asynchronous() // Applied as many times as it can in 1/60th of a second
this.diffuseStates('external_resources',0.1)
this.plotPopsizes('species', ['low uptake', 'medium uptake','high uptake'])
// Let's count some stuff every update
let sum_resources = 0
for (let i = 0; i < this.nc; i++) // i are columns
for (let j = 0; j < this.nr; j++) // j are rows
sum_resources+= this.grid[i][j].external_resources
// Update the plots. If the plot do not yet exist, a new plot will be automatically added by cacatoo
this.plotArray(["External resources"], [sum_resources/(this.nr*this.nc)], ["green"], "Resources")
if(this.time%240==0 && this.time > 0) {
sim.initialGrid(sim.growth,'external_resources',1000.0,1.0)
sim.growth.perfectMix()
for (let i = 0; i < this.nc; i++) // i are columns
for (let j = 0; j < this.nr; j++)
if(this.rng.genrand_real1() < 0.995){
sim.growth.grid[i][j].species = undefined
sim.growth.grid[i][j].uptake_rate=0.0
sim.growth.grid[i][j].internal_resources = 0
}
}
}
/*
OPTIONAL: Now that we have everything setup, we can also add some interactive elements (buttons or sliders). See cheater.html for more examples of this.
*/
sim.addButton("Play/pause sim", function () { sim.toggle_play() })
sim.addButton("Step", function () { sim.step(); sim.display() })
sim.start()
}
/*-------------------------End user-defined code ---------------------*/
</script>
</head>
<body onload="cacatoo()">
<!-- --------------------- START MENU. Couldnt get it to load dynamically, so this needs to be replaced in every HTML file upon changing --------------------- -->
<header class="header" id="btnNav"><buton class="header__button" id="btnNav" type="button"><i class="material-icons">menu</i></buton></header>
<nav class="nav"><div class="nav__links">
<a href="#" class="nav__head"><i id="btnNavclose" class="material-icons" style="cursor:pointer"> menu </i> Cacatoo </a>
<a href="index.html" id="nav__link" class="nav__link">Home</a>
<a href="https://github.com/bramvandijk88/cacatoo" id="nav__link" target="_blank" class="nav__link"> Source code (Github)</a>
<!-- <a href="https://replit.com/@bramvandijk88/Cacatoo-IBMs-with-examples" id="nav__link" target="_blank" class="nav__link"> Replit </a> -->
<a href="#" class="nav__head"><i class="material-icons"> play_circle_outline </i> Examples</a>
<a href="example_predator_prey.html" id="nav__link" class="nav__link"> Predator prey</a>
<a href="example_colony_growth.html" id="nav__link" class="nav__link"> Colony growth</a>
<a href="example_pheromones.html" id="nav__link" class="nav__link"> Ant pheromones</a>
<a href="example_aapjes.html" id="nav__link" class="nav__link"> Aapjes (monkeys)</a>
<a href="example_mutational_jackpot.html" id="nav__link" class="nav__link"> Mutational jackpot</a>
<a href="example_starlings.html" id="nav__link" class="nav__link"> Starlings</a> <a href="example_cooperation.html" id="nav__link" class="nav__link"> Cooperation</a>
<a href="example_TEs.html" id="nav__link" class="nav__link"> Transposon evolution</a>
<a href="examples_jsfiddle.html" id="nav__link" class="nav__link"> More examples (JSFiddle)</a>
<a href="#" class="nav__head"><i class="material-icons"> grid_on </i> How to Cacatoo </a>
<a href="overview.html" class="nav__link"> Tutorials (Blog style)</a>
<a href="list_of_options.html" class="nav__link"> All configuration options</a>
<a href="populating_the_simulation.html" class="nav__link"> Populating a simulation</a> <a href="display_and_colours.html" class="nav__link"> Display, colours, and UI</a>
<a href="neighbourhood_retrieval.html" class="nav__link"> Neighbourhood retrieval</a>
<a href="random_numbers.html" class="nav__link"> Using random numbers </a>
<a href="grid_events.html" class="nav__link"> Grid events</a>
<a href="working_with_odes.html" class="nav__link"> Working with ODEs</a>
<a href="jsdocs/index.html" id="nav__headlink" target="_blank" class="nav__headlink"><i class="material-icons">data_object </i> Full JS-Docs</a>
</div><div class="nav__overlay"></div></nav>
<script>
document.addEventListener("DOMContentLoaded", () => {
const nav = document.querySelector(".nav");
document.querySelector("#btnNav").addEventListener("click", () => {
nav.classList.add("nav--open");
});
document.querySelector(".nav__overlay").addEventListener("click", () => {
nav.classList.remove("nav--open");
});
document.querySelector("#btnNavclose").addEventListener("click", () => {
nav.classList.remove("nav--open");
});
var all_links = document.getElementsByClassName("nav__link");
var hide_menu = function() {
nav.classList.remove("nav--open");
};
for (var i = 0; i < all_links.length; i++) {
all_links[i].addEventListener('click', hide_menu, false);
}
});
</script>
<!-- --------------------- END MENU --------------------- -->
<div id="main">
<h1 class="page-title"><a href="https://github.com/bramvandijk88/cacatoo"><img src="images/elephant_cacatoo_small.png"></a> <b>Colony growth with consumer-resource dynamics</b> </img></h1>
A simple process of local growth, with a "serial transfer" every 240 time steps.
<center>
<div id="canvas_holder"></div>
<div id="form_holder"></div>
<div id="graph_holder">
</center>
<br><br>
</div>
<div id="Navigator"></div>
<br class="clear">
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>