cacatoo
Version:
Building, exploring, and sharing spatially structured models
140 lines (105 loc) • 4.9 kB
HTML
<!--
-->
<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: "Striped Turing patterns",
description: "\"<i>The stripes are easy, but what about the horse part?</i>\"<br>Draw on the grid to bleach the stripes.",
maxtime: 10000,
ncol: 300,
nrow: 100, // dimensions of the grid to build
wrap: [true, true], // Wrap boundary [COLS, ROWS]
scale: 2, // scale of the grid (nxn pixels per grid cell
show_gridname: true,
graph_interval: 5,
graph_update: 20,
printcursor: false,
bgcolour: 'white'
}
sim = new Simulation(config)
sim.makeGridmodel("turing")
sim.turing.colourGradient("activator", 200, [255,255,255], [0,0,0])
sim.createDisplay_continuous({model:"turing", property:"activator", label:"Activator density", // Createa a display for a continuous variable (ODE state for external resources)
minval:0, maxval:1, num_colours:200, decimals: 2})
let act = 0.5
let inh = 0.5
let d = 0.05
// Initialise the left 3 cols with activator and inhibitor
for (let i = 0; i < sim.turing.nc; i++)
for (let j = 0; j < sim.turing.nr; j++)
{
sim.turing.grid[i][j].activator = 1 + 50*sim.rng.genrand_real1()
sim.turing.grid[i][j].inhibitor = 1
}
// The nextState function has 3 steps: 1) ODE integration, 2) Diffusion, 3) Update what is displayed on the grid
sim.turing.nextState = function (x, y) // Define the next-state function.
{
let thisgp = this.grid[x][y]
let gp = thisgp //this.getNeighbour(this,i,j,1) // grid[i][j]
let act_new = gp.activator + (act * gp.activator - inh * gp.inhibitor - d * gp.activator * gp.activator)
let inh_new = gp.inhibitor + (act * gp.activator - inh * gp.inhibitor - d * gp.inhibitor * gp.inhibitor)
thisgp.activator = act_new > 0 ? act_new : 0
thisgp.inhibitor = inh_new > 0 ? inh_new : 0
}
sim.turing.update = function () {
this.asynchronous()
this.diffuseStates('inhibitor',0.3)
this.diffuseStates('activator',0.15)
}
sim.addButton("pause", function () { sim.toggle_play() })
sim.addButton("mix grid", function () { sim.turing.perfectMix() })
sim.start()
//// BELOW IS SOME STUFF TO REMOVE ACTIVATOR WITH THE MOUSE
var mouseDown = false
var coords
var coords_previous
var interval
sim.place_value = 0
sim.place_size = 250
//// BELOW IS A MODIFIED VERSION OF THE 'diffuseStates' FUNCTION, which avoids exchange with left
sim.turing.diffuseStates = function(state,rate)
{
if(rate > 0.5) {
throw new Error("Cacatoo: rate for diffusion cannot be greater than 0.5, try multiple diffusion steps instead.")
}
let newstate = MakeGrid(this.nc, this.nr, this.grid);
for (let i = 0; i < this.nc; i += 1) // every column
{
for (let j = 0; j < this.nr; j += 1) // every row
{
//newstate[i][j] = this.grid[i][j][state]
for (let n = 1; n <= 4; n++) // Every neighbour (neumann)
{
if(n==2) continue // Do not exchange with (diffuse to) the right-hand side
let moore = this.moore[n];
let xy = this.getNeighXY(i + moore[0], j + moore[1]);
if (typeof xy == "undefined") continue
let neigh = this.grid[xy[0]][xy[1]];
newstate[i][j][state] += neigh[state] * rate;
newstate[xy[0]][xy[1]][state] -= neigh[state] * rate;
}
}
}
for (let i = 0; i < this.nc; i += 1) // every column
for (let j = 0; j < this.nr; j += 1) // every row
for (let n = 1; n <= 4; n++) this.grid[i][j][state] = newstate[i][j][state];
}
sim.addStatebrush(sim.turing, "activator",0.000,200)
}
/*-------------------------End user-defined code ---------------------*/
</script>
<body onload="cacatoo()">
<div class="header" id="header"></div>
<div class="content" id="canvas_holder"> </div>
<div class="content" id="graph_holder"> </div>
<div class="content" id="form_holder"> </div>
<div class="content" id="output"> </div>
<div class="footer" id="footer"></div>
</body>
</html>