<!--
###########################################################################################
This is a JSFiddle example of "Cacatoo". This HTML page does not contain the code itself,
but determines where the grids, graphs, buttons, etc are placed. The real code is in the
Javascript Tab. I recommend enabling "Tabs (Columns)" under the settings in the top-right.
###########################################################################################
-->
<html>
<script src="https://bramvandijk88.github.io/cacatoo/scripts/cacatoo.js"></script>
<script src="https://bramvandijk88.github.io/cacatoo/scripts/all.js"></script>
<!-- Dependencies
<link rel="stylesheet" href="style.css"> <!-- Set style sheet -->
<head>
<title>Cacatoo examples</title>
</head>
<script>
/*-------------------------End user-defined code ---------------------*/
</script>
<body onload="cacatoo()">
<div class="header" id="header">
<h2>Cacatoo (example project)</h2>
</div>
<div class="content" id="canvas_holder"> </div>
<div class="content" id="graph_holder"> </div>
<div class="content" id="form_holder"></div>
<div class="footer" id="footer"></div>
</body>
</html>
let sim;
function cacatoo() {
let config = {
title: "Rock-paper-scissors",
description: "Rock beats scissors, scissors beats paper, and paper beats... rock. Apparently.<br>This example illustrates how you can add mouse events and key press events. <br>Use your mouse to draw, and chance colours with the '1', '2,' and '3' keys.<br> The '[' and ']' keys can modify the brush size.",
maxtime: 10000,
seed:1,
ncol: 300,
nrow: 300, // dimensions of the grid to build
wrap: [false, false], // Wrap boundary [COLS, ROWS]
scale: 1, // scale of the grid (nxn pixels per grid cell)
statecolours: { colour: {1:'white',2:'red',3:'blue'} }, // if set to 'default', createDisplay (below) inherits the default colours of cacatoo
num_colours: 3,
printcursor: false
}
sim = new Simulation(config)
sim.makeGridmodel("spirals");
sim.createDisplay("spirals", "colour", "Colours represent different species")
// sim.spirals.canvases["Colours represent different species"].legend.style.display = "none" // Hack to remove the legend :)
let n_species = 3
// sim.initialGrid(sim.spirals,'colour',0,2,0.01)
for (let x = 0; x < sim.spirals.nc; x++) // x are columns
for (let y = 0; y < sim.spirals.nr; y++) // y are rows
//sim.spirals.grid[x][y]['colour'] = Math.ceil(sim.rng.genrand_real1() * n_species)
sim.spirals.grid[x][y].colour = 1
sim.spirals.nextState = function (x, y) // Define the next-state function. This example is spirals
{
let state = this.grid[x][y].colour // Colour of current pixel
let pred = (this.grid[x][y].colour % n_species) + 1 // Colour it is...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.