cacatoo
Version:
Building, exploring, and sharing spatially structured models
81 lines (58 loc) • 3 kB
HTML
<!--
EXAMPLE FILE 02: Modulo prime
Every pixel counts how many white pixels it has, and its next state
will be the modulo of 2 (0=0,1=1,2=0,3=1,4=0, etc.). You may notice
this example doesn't run automatically. Instead, you can load up your
own initial pattern (see 'patterns' folder), and go through it step
by step.
-->
<!-- ---------------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 simulation;
function cacatoo() {
let config = {
title: "Modulo prime",
description: "Update rule: next_state = n_neighbours % 2",
maxtime: 100000000,
ncol: 100,
nrow: 100, // dimensions of the grid to build
sleep: 200,
wrap: [true, true], // Wrap boundary [COLS, ROWS]
scale: 4, // scale of the grid (nxn pixels per grid cell)
statecolours: { 'alive': { 1: 'white' } }, // Only defining the "alive" state, while...
}
sim = new Simulation(config) // Initialise a new sim instance with configuration given above
sim.makeGridmodel("prime");
sim.createDisplay("prime", "alive", "Modulo prime")
// Note to user: initialPattern is disabled, as it requirs a webserver for security reasons. You can also use the pattern button instead, or take a look at the draw_gol.html example where you can draw your own starting pattern.
// sim.initialPattern(sim.prime, 'alive', '../patterns/elephant_cacatoo.png', 115, 115)
sim.prime.grid[50][50].alive=1
sim.prime.nextState = function (x, y) // Define the next-state function. This example is modulo prime
{
this.grid[x][y].alive = (this.countMoore8(this, x, y, 'alive',1) % 2 == 0 ? 0 : 1)
}
sim.prime.update = function () {
this.synchronous()
}
// Adds a pattern load button
sim.addPatternButton(sim.prime, 'alive')
sim.addButton("pause/continue", function () { sim.toggle_play() })
sim.addButton("step", function () { sim.step(); sim.display() })
sim.start()
}
</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>