cacatoo
Version:
Building, exploring, and sharing spatially structured models
2,636 lines (597 loc) • 29.9 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: Simulation</title>
<link rel="icon" type="image/png" href="images/favicon.png" />
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<script src="scripts/jquery.js"></script>
<script>
$(function(){
$("#Navigator").load("navigator.html");
});
</script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: Simulation</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>Simulation<span class="signature">(config)</span><span class="type-signature"></span></h2>
<div class="class-description">Simulation is the global class of Cacatoo, containing the main configuration
for making a grid-based model grid and displaying it in either browser or with
nodejs.</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="Simulation"><span class="type-signature"></span>new Simulation<span class="signature">(config)</span><span class="type-signature"></span></h4>
<div class="description">
The constructor function for a @Simulation object. Takes a config dictionary.
and sets options accordingly.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>config</code></td>
<td class="type">
<span class="param-type">dictionary</span>
</td>
<td class="description last">A dictionary (object) with all the necessary settings to setup a Cacatoo simulation.</td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line1328">line 1328</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="addButton"><span class="type-signature"></span>addButton<span class="signature">(text, func)</span><span class="type-signature"></span></h4>
<div class="description">
addButton adds a HTML button which can be linked to a function by the user.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>text</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Text displayed on the button</td>
</tr>
<tr>
<td class="name"><code>func</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last">Function to be linked to the button</td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line1573">line 1573</a>
</li></ul></dd>
</dl>
<h4 class="name" id="addPatternButton"><span class="type-signature"></span>addPatternButton<span class="signature">({@GridModel}, property)</span><span class="type-signature"></span></h4>
<div class="description">
addPatternButton adds a pattern button to the HTML environment which allows the user
to load a PNG which then sets the state of 'proparty' for the @GridModel.
(currently only supports black and white image)
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>{@GridModel}</code></td>
<td class="type">
</td>
<td class="description last">targetgrid The gridmodel containing the grid to be modified.</td>
</tr>
<tr>
<td class="name"><code>property</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The name of the state to be set</td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line1655">line 1655</a>
</li></ul></dd>
</dl>
<h4 class="name" id="addSlider"><span class="type-signature"></span>addSlider<span class="signature">(parameter, min<span class="signature-attributes">opt</span>, max<span class="signature-attributes">opt</span>, step<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
addSlider adds a HTML slider to the DOM-environment which allows the user
to modify a model parameter at runtime.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>parameter</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">The name of the (global!) parameter to link to the slider</td>
</tr>
<tr>
<td class="name"><code>min</code></td>
<td class="type">
<span class="param-type">float</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
0
</td>
<td class="description last">Minimal value of the slider</td>
</tr>
<tr>
<td class="name"><code>max</code></td>
<td class="type">
<span class="param-type">float</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
2
</td>
<td class="description last">Maximum value of the slider</td>
</tr>
<tr>
<td class="name"><code>step</code></td>
<td class="type">
<span class="param-type">float</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
0.01
</td>
<td class="description last">Step-size when modifying</td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line1590">line 1590</a>
</li></ul></dd>
</dl>
<h4 class="name" id="colourRamp"><span class="type-signature"></span>colourRamp<span class="signature">(arr1, arr2, n)</span><span class="type-signature"> → {dict}</span></h4>
<div class="description">
colourRamp interpolates between two arrays to get a smooth colour scale.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>arr1</code></td>
<td class="type">
<span class="param-type">array</span>
</td>
<td class="description last">Array of R,G,B values to start fromtargetgrid The gridmodel containing the grid to be modified.</td>
</tr>
<tr>
<td class="name"><code>arr2</code></td>
<td class="type">
<span class="param-type">array</span>
</td>
<td class="description last">Array of R,B,B values to transition towards</td>
</tr>
<tr>
<td class="name"><code>n</code></td>
<td class="type">
<span class="param-type">integer</span>
</td>
<td class="description last">number of steps taken</td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line1776">line 1776</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
A dictionary (i.e. named JS object) of colours
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">dict</span>
</dd>
</dl>
<h4 class="name" id="createDisplay"><span class="type-signature"></span>createDisplay<span class="signature">(name, property, height, width, scale)</span><span class="type-signature"></span></h4>
<div class="description">
Create a display for a gridmodel, showing a certain property on it.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The name of an existing gridmodel to display</td>
</tr>
<tr>
<td class="name"><code>property</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The name of the property to display</td>
</tr>
<tr>
<td class="name"><code>height</code></td>
<td class="type">
<span class="param-type">integer</span>
</td>
<td class="description last">Number of rows to display (default = ALL)</td>
</tr>
<tr>
<td class="name"><code>width</code></td>
<td class="type">
<span class="param-type">integer</span>
</td>
<td class="description last">Number of cols to display (default = ALL)</td>
</tr>
<tr>
<td class="name"><code>scale</code></td>
<td class="type">
<span class="param-type">integer</span>
</td>
<td class="description last">Scale of display (default inherited from @Simulation class)</td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line1371">line 1371</a>
</li></ul></dd>
</dl>
<h4 class="name" id="display"><span class="type-signature"></span>display<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Display all the canvases linked to this simulation
</div>
<dl class="details">
<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#line1464">line 1464</a>
</li></ul></dd>
</dl>
<h4 class="name" id="events"><span class="type-signature"></span>events<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Apply global events to all grids in the model.
(only perfectmix currently... :D)
</div>
<dl class="details">
<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#line1453">line 1453</a>
</li></ul></dd>
</dl>
<h4 class="name" id="getCursorPosition"><span class="type-signature"></span>getCursorPosition<span class="signature">(canvas, event, scale)</span><span class="type-signature"></span></h4>
<div class="description">
Create a display for a gridmodel, showing a certain property on it.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>canvas</code></td>
<td class="type">
<span class="param-type">canvas</span>
</td>
<td class="description last">A (constant) canvas object</td>
</tr>
<tr>
<td class="name"><code>event</code></td>
<td class="type">
<span class="param-type">event-handler</span>
</td>
<td class="description last">Event handler (mousedown)</td>
</tr>
<tr>
<td class="name"><code>scale</code></td>
<td class="type">
<span class="param-type">scale</span>
</td>
<td class="description last">The zoom (scale) of the grid to grab the correct grid point</td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line1397">line 1397</a>
</li></ul></dd>
</dl>
<h4 class="name" id="initialGrid"><span class="type-signature"></span>initialGrid<span class="signature">({@GridModel}, property, value, fraction)</span><span class="type-signature"></span></h4>
<div class="description">
initialGrid populates a grid with states. The number of arguments
is flexible and defined the percentage of every state. For example,
initialGrid('grid','species',1,0.5,2,0.25) populates the grid with
two species (1 and 2), where species 1 occupies 50% of the grid, and
species 2 25%.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>{@GridModel}</code></td>
<td class="type">
</td>
<td class="description last">grid The gridmodel containing the grid to be modified.</td>
</tr>
<tr>
<td class="name"><code>property</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The name of the state to be set</td>
</tr>
<tr>
<td class="name"><code>value</code></td>
<td class="type">
<span class="param-type">integer</span>
</td>
<td class="description last">The value of the state to be set (optional argument with position 2, 4, 6, ..., n)</td>
</tr>
<tr>
<td class="name"><code>fraction</code></td>
<td class="type">
<span class="param-type">float</span>
</td>
<td class="description last">The chance the grid point is set to this state (optional argument with position 3, 5, 7, ..., n)</td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line1552">line 1552</a>
</li></ul></dd>
</dl>
<h4 class="name" id="initialPattern"><span class="type-signature"></span>initialPattern<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
initialPattern takes a @GridModel and loads a pattern from a PNG file. Note that this
will only work when Cacatoo is ran on a server due to security issues. If you want to
use this feature locally, there are plugins for most browser to host a simple local
webserver.
(currently only supports black and white image)
</div>
<dl class="details">
<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#line1715">line 1715</a>
</li></ul></dd>
</dl>
<h4 class="name" id="makeGridmodel"><span class="type-signature"></span>makeGridmodel<span class="signature">(name)</span><span class="type-signature"></span></h4>
<div class="description">
Generate a new GridModel within this simulation.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The name of your new model, e.g. "gol" for game of life. Cannot contain whitespaces.</td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line1355">line 1355</a>
</li></ul></dd>
</dl>
<h4 class="name" id="plotXY"><span class="type-signature"></span>plotXY<span class="signature">(name, property, height, width, scale)</span><span class="type-signature"></span></h4>
<div class="description">
Create a dygraphs XY graph, showing an arbitrary number of
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The name of an existing gridmodel to display</td>
</tr>
<tr>
<td class="name"><code>property</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The name of the property to display</td>
</tr>
<tr>
<td class="name"><code>height</code></td>
<td class="type">
<span class="param-type">integer</span>
</td>
<td class="description last">Number of rows to display (default = ALL)</td>
</tr>
<tr>
<td class="name"><code>width</code></td>
<td class="type">
<span class="param-type">integer</span>
</td>
<td class="description last">Number of cols to display (default = ALL)</td>
</tr>
<tr>
<td class="name"><code>scale</code></td>
<td class="type">
<span class="param-type">integer</span>
</td>
<td class="description last">Scale of display (default inherited from @Simulation class)</td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line1418">line 1418</a>
</li></ul></dd>
</dl>
<h4 class="name" id="start"><span class="type-signature"></span>start<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Start the simulation. start() detects whether the user is running the code from the browser of
in nodejs. In the browser, a GUI is provided to interact with the model. In nodejs the
programmer can simply wait for the result without wasting time on displaying intermediate stuff
(which can be slow)
</div>
<dl class="details">
<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#line1476">line 1476</a>
</li></ul></dd>
</dl>
<h4 class="name" id="step"><span class="type-signature"></span>step<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Update all the grid models one step. Apply optional mixing
</div>
<dl class="details">
<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#line1443">line 1443</a>
</li></ul></dd>
</dl>
<h4 class="name" id="toggle_mix"><span class="type-signature"></span>toggle_mix<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Toggle the mix option
</div>
<dl class="details">
<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#line1753">line 1753</a>
</li></ul></dd>
</dl>
<h4 class="name" id="toggle_play"><span class="type-signature"></span>toggle_play<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Toggle the pause option. Restart the model if pause is disabled.
</div>
<dl class="details">
<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#line1762">line 1762</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<div id="Navigator"></div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Wed Jul 28 2021 15:33:33 GMT+0200 (Central European Summer Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>