Constructor
new Simulation(config)
The constructor function for a @Simulation object. Takes a config dictionary.
and sets options accordingly.
Parameters:
| Name | Type | Description |
|---|---|---|
config |
dictionary | A dictionary (object) with all the necessary settings to setup a Cacatoo simulation. |
- Source:
Methods
addButton(text, func)
addButton adds a HTML button which can be linked to a function by the user.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string | Text displayed on the button |
func |
function | Function to be linked to the button |
- Source:
addPatternButton({@GridModel}, property)
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)
Parameters:
| Name | Type | Description |
|---|---|---|
{@GridModel} |
targetgrid The gridmodel containing the grid to be modified. | |
property |
String | The name of the state to be set |
- Source:
addSlider(parameter, minopt, maxopt, stepopt)
addSlider adds a HTML slider to the DOM-environment which allows the user
to modify a model parameter at runtime.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
parameter |
string | The name of the (global!) parameter to link to the slider | ||
min |
float |
<optional> |
0 | Minimal value of the slider |
max |
float |
<optional> |
2 | Maximum value of the slider |
step |
float |
<optional> |
0.01 | Step-size when modifying |
- Source:
colourRamp(arr1, arr2, n) → {dict}
colourRamp interpolates between two arrays to get a smooth colour scale.
Parameters:
| Name | Type | Description |
|---|---|---|
arr1 |
array | Array of R,G,B values to start fromtargetgrid The gridmodel containing the grid to be modified. |
arr2 |
array | Array of R,B,B values to transition towards |
n |
integer | number of steps taken |
- Source:
Returns:
A dictionary (i.e. named JS object) of colours
- Type
- dict
createDisplay(name, property, height, width, scale)
Create a display for a gridmodel, showing a certain property on it.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The name of an existing gridmodel to display |
property |
string | The name of the property to display |
height |
integer | Number of rows to display (default = ALL) |
width |
integer | Number of cols to display (default = ALL) |
scale |
integer | Scale of display (default inherited from @Simulation class) |
- Source:
display()
Display all the canvases linked to this simulation
- Source:
events()
Apply global events to all grids in the model.
(only perfectmix currently... :D)
- Source:
getCursorPosition(canvas, event, scale)
Create a display for a gridmodel, showing a certain property on it.
Parameters:
| Name | Type | Description |
|---|---|---|
canvas |
canvas | A (constant) canvas object |
event |
event-handler | Event handler (mousedown) |
scale |
scale | The zoom (scale) of the grid to grab the correct grid point |
- Source:
initialGrid({@GridModel}, property, value, fraction)
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%.
Parameters:
| Name | Type | Description |
|---|---|---|
{@GridModel} |
grid The gridmodel containing the grid to be modified. | |
property |
String | The name of the state to be set |
value |
integer | The value of the state to be set (optional argument with position 2, 4, 6, ..., n) |
fraction |
float | The chance the grid point is set to this state (optional argument with position 3, 5, 7, ..., n) |
- Source:
initialPattern()
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)
- Source:
makeGridmodel(name)
Generate a new GridModel within this simulation.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The name of your new model, e.g. "gol" for game of life. Cannot contain whitespaces. |
- Source:
plotXY(name, property, height, width, scale)
Create a dygraphs XY graph, showing an arbitrary number of
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The name of an existing gridmodel to display |
property |
string | The name of the property to display |
height |
integer | Number of rows to display (default = ALL) |
width |
integer | Number of cols to display (default = ALL) |
scale |
integer | Scale of display (default inherited from @Simulation class) |
- Source:
start()
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)
- Source:
step()
Update all the grid models one step. Apply optional mixing
- Source:
toggle_mix()
Toggle the mix option
- Source:
toggle_play()
Toggle the pause option. Restart the model if pause is disabled.
- Source: