cacatoo
Version:
Building, exploring, and sharing spatially structured models
94 lines (70 loc) • 4.2 kB
HTML
<!--
EXAMPLE FILE: Diffusion limited aggregation (DLA)
-->
<!-- ---------------Do not change the part below ------------------ -->
<html>
<script src="../../dist/cacatoo.js"></script> <!-- Include cacatoo library (compiled with rollup) -->
<script src="../../lib/all.js"></script> <!-- Load other packages -->
<link rel="stylesheet" href="../../style/cacatoo.css"> <!-- Set style sheet -->
<script>
/*-----------------------Start user-defined code ---------------------*/
let sim;
function cacatoo()
{
let config =
{
title: "Diffusion limited aggregation", // The name of your cacatoo-simulation
description: "", // And a description if you wish
maxtime: 1000000, // How many time steps the model continues to run
skip: 5, // Skip 5 frames before re-drawing the grid
ncol : 150, // Number of columns (width of your grid)
nrow : 150, // Number of rows (height of your grid)
wrap : [false, false], // Wrapped boundary conditions? [COLS, ROWS]
scale : 2, // Scale of the grid (nxn pixels per grid point)
statecolours: {'state':{'dead':'black',
'alive':'white'},
'food':{'no food':'black','food':'white'},
'colour':'inferno'}, // Colours for each state. Background (0) defaults to black.
}
sim = new Simulation(config) // Initialise the Cacatoo simulation
sim.makeGridmodel("growth") // Build a new Gridmodel within the simulation called "growth"
sim.makeGridmodel("particles") // Build a new Gridmodel within the simulation called "particles"
sim.initialGrid(sim.growth,'state',0,'dead',1.0) // Set all Grid points in 'growth' to 'dead' ...
sim.growth.grid[config.ncol/2][config.nrow/2].state = 'alive' // ... except for 1 grid point in the middle which is 'alive'
sim.initialGrid(sim.particles,'food',0.0,'food',0.25) // Set 25% of the Gridmodel 'particle' to 'food'
sim.createDisplay("growth","colour","Growing aggregate")
sim.createDisplay("particles","food","Available food particles") // Create a display so we can see our newly made gridmodel
sim.growth.nextState = function(x,y)
{
if(this.grid[x][y].state == 'dead'){
if(sim.particles.grid[x][y].food=='food' && this.countMoore8(sim.growth,x,y,'state','alive') > 0){
sim.particles.grid[x][y].food = 'no food'
this.grid[x][y].state = 'alive'
this.grid[x][y].colour = Math.min(18,1+Math.floor(this.time/10))
}
}
}
sim.particles.nextState = function(x,y) { }
sim.growth.update = function()
{
this.synchronous()
}
sim.particles.update = function()
{
this.MargolusDiffusion()
}
sim.addMovieButton(sim.growth, "Growing aggregate",60)
sim.start()
}
/*-------------------------End user-defined code ---------------------*/
</script>
<body onload="cacatoo()">
<div class="header" id="header">
<h2>Cacatoo </h2>
</div>
<div class="content" id="canvas_holder"></div>
<div class="content" id="form_holder"></div>
<div class="content" id="graph_holder"> </div>
<div class="footer" id="footer"></div>
</body>
</html>