Skip to content

Commit

Permalink
One more example
Browse files Browse the repository at this point in the history
  • Loading branch information
bramvandijk88 committed Jan 18, 2022
1 parent fe3ac85 commit be3a412
Show file tree
Hide file tree
Showing 25 changed files with 4,129 additions and 351 deletions.
3 changes: 3 additions & 0 deletions cacatodo.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
(caca)TODO
> Option and example for serialising objects
> Example of writing stuff to file and plot is with an Rscript
> Modify hamburger menu in DOCs for small screens
> Push data to graphs rather then completely reload it (not sure dygraphs allows for this, but could check)
> FBA testing
> Implement d3.js visualization like histograms / phylogenetic trees.
57 changes: 31 additions & 26 deletions dist/cacatoo.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ class Gridmodel {
constructor(name, config, rng) {
this.name = name;
this.time = 0;
this.grid = MakeGrid(config.ncol, config.nrow); // Initialises an (empty) grid
this.nc = config.ncol || 200;
this.nr = config.nrow || 200;
this.grid = MakeGrid(this.nc, this.nr); // Initialises an (empty) grid
this.wrap = config.wrap || [true, true];
this.rng = rng;
this.random = () => { return this.rng.genrand_real1()};
Expand Down Expand Up @@ -361,6 +361,14 @@ class Gridmodel {
this.canvases = {}; // Object containing all Canvases belonging to this model (HTML usage only)
}

/** Replaces current grid with an empty grid */
clearGrid()
{
this.grid = MakeGrid(this.nc,this.nr);

}


/** Initiate a dictionary with colour arrays [R,G,B] used by Graph and Canvas classes
* @param {statecols} object - given object can be in two forms
* | either {state:colour} tuple (e.g. 'alive':'white', see gol.html)
Expand Down Expand Up @@ -818,30 +826,30 @@ class Gridmodel {
* @param {int} row position (row) for the focal gridpoint
* @param {Array} range from which to sample (1-8 is Moore8, 0-4 is Neu5, etc.)
*/
randomMoore(grid, col, row,range) {
randomNeighbour(grid, col, row,range) {
let rand = this.rng.genrand_int(range[0], range[1]);
let i = this.moore[rand][0];
let j = this.moore[rand][1];
let neigh = grid.getGridpoint(col + i, row + j);
while (neigh == undefined) neigh = this.randomMoore(grid, col, row,range);
while (neigh == undefined) neigh = this.randomNeighbour(grid, col, row,range);
return neigh
}

/** randomMoore for range 1-8 (see randomMoore) */
randomMoore8(model, col, row) { return this.randomMoore(model, col, row, [1,8]) }
randomNeighbour8(model, col, row) { return this.randomMoore(model, col, row, [1,8]) }
randomMoore8(model, col, row) { return this.randomNeighbour(model, col, row, [1,8]) }
randomNeighbour8(model, col, row) { return this.randomNeighbour(model, col, row, [1,8]) }

/** randomMoore for range 0-8 (see randomMoore) */
randomMoore9(model, col, row) { return this.randomMoore(model, col, row, [0,8]) }
randomNeighbour9(model, col, row) { return this.randomMoore(model, col, row, [0,8]) }
randomMoore9(model, col, row) { return this.randomNeighbour(model, col, row, [0,8]) }
randomNeighbour9(model, col, row) { return this.randomNeighbour(model, col, row, [0,8]) }

/** randomMoore for range 1-4 (see randomMoore) */
randomNeumann4(model, col, row) { return this.randomMoore(model, col, row, [1,4]) }
randomNeighbour4(model, col, row) { return this.randomMoore(model, col, row, [1,4]) }
randomNeumann4(model, col, row) { return this.randomNeighbour(model, col, row, [1,4]) }
randomNeighbour4(model, col, row) { return this.randomNeighbour(model, col, row, [1,4]) }

/** randomMoore for range 0-4 (see randomMoore) */
randomNeumann5(model, col, row) { return this.randomMoore(model, col, row, [0,4]) }
randomNeighbour5(model, col, row) { return this.randomMoore(model, col, row, [0,4]) }
randomNeumann5(model, col, row) { return this.randomNeighbour(model, col, row, [0,4]) }
randomNeighbour5(model, col, row) { return this.randomNeighbour(model, col, row, [0,4]) }


/** Diffuse continuous states on the grid.
Expand Down Expand Up @@ -1774,19 +1782,19 @@ class Simulation {
* and sets options accordingly.
* @param {dictionary} config A dictionary (object) with all the necessary settings to setup a Cacatoo simulation.
*/
constructor(config) {
this.config = config;
constructor(config) {
if(config == undefined) config = {};
this.config = config;
this.rng = new MersenneTwister(config.seed || 53);

this.sleep = config.sleep || 0;
this.maxtime = config.maxtime || 1000000;
this.ncol = config.ncol || 100;
this.nrow = config.nrow || 100;

this.scale = config.scale || 2;
this.maxtime = config.maxtime || 1000000;
this.graph_interval = config.graph_interval || 10;
this.graph_update = config.graph_update || 50;
this.sleep = config.sleep = config.sleep || 0;
this.maxtime = config.maxtime = config.maxtime || 1000000;
this.ncol = config.ncol = config.ncol || 100;
this.nrow = config.nrow = config.nrow || 100;
this.scale = config.scale = config.scale || 2;

this.graph_interval = config.graph_interval = config.graph_interval || 10;
this.graph_update = config.graph_update= config.graph_update || 50;
this.fps = config.fps * 1.4 || 60;
// Three arrays for all the grids ('CAs'), canvases ('displays'), and graphs
this.gridmodels = []; // All gridmodels in this simulation
Expand All @@ -1797,9 +1805,7 @@ class Simulation {
this.printcursor = true;
this.fpsmeter = false;
if(config.fpsmeter == true) this.fpsmeter = true;
if(config.printcursor == false) this.printcursor = false;


if(config.printcursor == false) this.printcursor = false;
}

/**
Expand Down Expand Up @@ -2231,7 +2237,6 @@ class Simulation {

}


/**
* addButton adds a HTML button which can be linked to a function by the user.
* @param {string} text Text displayed on the button
Expand Down
1 change: 1 addition & 0 deletions docs/adding_ui_elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<!-- --------------------- START MENU. Couldnt get it to load dynamically, so this needs to be replaced in every HTML file upon changing --------------------- -->
<header class="header" id="btnNav"><buton class="header__button" id="btnNav" type="button"><i class="material-icons">menu</i></buton></header>


<nav class="nav"><div class="nav__links">
<a href="#" class="nav__head"><i id="btnNavclose" class="material-icons" style="cursor:pointer"> menu </i> Cacatoo </a>
<a href="index.html" id="nav__link" class="nav__link">Home</a>
Expand Down
6 changes: 3 additions & 3 deletions docs/jsdocs/Canvas.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1337">line 1337</a>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1345">line 1345</a>
</li></ul></dd>


Expand Down Expand Up @@ -346,7 +346,7 @@ <h4 class="name" id="displaygrid"><span class="type-signature"></span>displaygri

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1383">line 1383</a>
<a href="cacatoo.js.html">cacatoo.js</a>, <a href="cacatoo.js.html#line1391">line 1391</a>
</li></ul></dd>


Expand Down Expand Up @@ -398,7 +398,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Canvas.ht
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Jan 06 2022 09:56:10 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Tue Jan 18 2022 15:01:00 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/jsdocs/Graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Canvas.ht
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Jan 06 2022 09:56:10 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Tue Jan 18 2022 15:01:00 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading

0 comments on commit be3a412

Please sign in to comment.