Cacatoo - Spiral course

by bramvandijk88

HTML

<!-- 
  ###########################################################################################
    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()">

		
		<table align="center" border=0>
		<tr>
		<td  ><div class="content" id="canvas_holder"> </div></td>
		<td ><div class="content" id="graph_holder"> </div></td>
		</tr>
		</table>
		
    <div class="content" id="form_holder"> </div>

  </body>

</html>

CSS

body {
  font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
  background-color: #e2e2e2;
  margin: 0px;
	padding: 0px;
  font-size: 13px;
}

/* Style the header */
.header {
  background-color: rgb(111, 146, 170);
  display: block;
  border: 0px solid #FFFFFF;
  box-shadow: 3px 1px 0px #24242444;
  border-radius: 15px 15px 0px 0px;
  padding: 10px;
  text-align: center;
  font-size: 20px;
  font-weight: 900;
  color: #ffffff;
}


.logos {
  z-index: -1;
  vertical-align: middle;
  display: inline-block;
  padding-left: 10px;
  padding-top: 10px;
}

.example_card {
  width: 220px;
  height: 220px;
  background-color: rgb(151, 183, 204);
  box-shadow: rgba(100, 100, 111, 0.1) 20px 7px 29px 0px;
  /* font-weight: bold; */
  color: rgb(229, 239, 245);
  font-size: 12px;
  line-height: 25px;
  margin: 25px;
  padding: 20px;
  padding-bottom: 40px;
  padding-top: 10px;
  border-radius: 0px 0px 0px 0px;
  display: inline-block;
  transition: all 100ms ease-out 200ms;
  transition-delay: 0s;
}

.example_card_img {
  width: 100%;
  height: 100%;
  border-radius: 0px 0px 0px 0px;
  background-position: 45% 50%;
  background-repeat: no-repeat;
  background-size: cover;
}

.example_card:hover {
  background-color: rgb(151, 183, 204);
  font-size: 12px;
  color: black;
  border-radius: 30px 0px 30px 0px;
  box-shadow: rgba(100, 100, 111, 0.3) 0px 0px 29px 0px;
}

.example_card:active {
  background-color: rgb(151, 183, 204);
  font-size: 12px;
  padding-top: 11px;
  height: 199px;
  color: black;
  box-shadow: rgba(100, 100, 111, 0.3) 0px 0px 29px 0px;
}


/* Content (grid, graphs, sliders) */
.content {
  text-align: center;
 /*  box-shadow: 3px 1px 0px #24242444; */
  /*border-bottom: 1px dashed #88888844;*/
  background-color: #e2e2e2;
  padding: 10px;
	margin: 10px;
}

/* Output div */
.output {
  border-radius: 8px 8px 8px 8px;
  margin: 30px;
  height: 300px;
  overflow-y: scroll;
  font-size: 11px;
 ...

JavaScript

/*-----------------------Start user-defined code ---------------------*/
    

let sim; // Declare a variable named "sim" globally, so that we can access our cacatoo-simulation from wherever we need. 
var b = 0.13
var c = 0.11
var d = 0.1
var init_density=0.05
var mengen = 1
var perfect = 0
function cacatoo() {
  
  let config = {
    title: "Growth", // 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: 100, // Number of columns (width of your grid)
    nrow: 100, // Number of rows (height of your grid)
    wrap: [true, true], // Wrapped boundary conditions? [COLS, ROWS]   
    scale: 2, // Scale of the grid (nxn pixels per grid point)
    graph_update: 1,
    graph_interval: 5,
		seed: 12,
		sleep:0,
		bgcolour: "white",
    statecolours: {
      'type': {
        1: 'blue',
				2: 'red',
				3: 'orange'
      }
    }, // Colours for each state. Background (0) defaults to black. 
  }

  
  sim = new Simulation(config) 
  sim.makeGridmodel("growth") 
  sim.mengen = 0

	sim.reset = function(){
  	sim.initialGrid(sim.growth,"type",0,1,init_density,2,init_density,3,init_density)
		sim.growth.resetPlots()
	}
//	sim.initialSpot(sim.growth, "heck", 1, 2, sim.config.ncol/2, sim.config.nrow/2)
	sim.reset()

  //sim.createDisplay("growth", "heck", "Heck runderen") // Create a display so we can see our newly made gridmodel
  sim.createDisplay_discrete({
    model: "growth",
    property: "type",
    drawdots: true,
		stroke:true, strokeStyle: 'black', strokeWidth: 0.5,
    radius: 2.2,
    label: "Rock-paper-scissors!"
  })
  sim.growth.nextState = function(i, j) {
		let gp = this.grid[i][j]
		if(gp.type==0) return
		else{
			let self = gp.type
			let other = (gp.type%3) + 1
	    let neigh = this.randomMoore8(this, i, j)
			let numneigh = this.countMoore8(this, i, j, "type", other)
			if(neigh.type==0 && sim.rng.random() < b+numneigh*c){
				neigh.type...