Methods
CopyGridODEs(cols, rows, template)
Make a back-up of all the ODE states (for synchronous ODE updating)
Parameters:
| Name | Type | Description |
|---|---|---|
cols |
int | Width of the grid |
rows |
int | Height of the grid |
template |
2DArray | Get ODE states from here |
- Source:
MakeGrid(cols, rows, template)
Make a grid, or when a template is given, a COPY of a grid.
Parameters:
| Name | Type | Description |
|---|---|---|
cols |
int | Width of the new grid |
rows |
int | Height of the new grid |
template |
2DArray | Template to be used for copying (if not set, a new empty grid is made) |
- Source:
applyKernelFFT(gridmodel, readProp, writeProp, kernelObj, scaleopt)
Apply a 2-D FFT convolution to one numeric state of every gridpoint.
Reads from readProp, writes to writeProp (may be the same property).
Low-level engine used by diffuseStatesFFT and castDiskFFT.
Works in both browser and Node.js.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
gridmodel |
object | |||
readProp |
string | |||
writeProp |
string | |||
kernelObj |
Object | |||
scale |
number |
<optional> |
1 |
- Source:
copy(aObject)
Deep copy function.
Parameters:
| Name | Type | Description |
|---|---|---|
aObject |
Object | Object to be deep copied. This function still won't deep copy every possible object, so when enabling deep copying, make sure you put your debug-hat on! |
- Source:
default_colours()
Compile a dict of default colours if nothing is given by the user. Reuses colours if more colours are needed.
- Source:
dict_reverse(obj)
Reverse dictionary
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
Object | dictionary-style object to reverse in order |
- Source:
diffuseStateGPU(gridmodel, state, kernelObj)
Diffuse a continuous state using GPU (WebGL2) separable Gaussian convolution.
Two fragment shader passes (H then V). Faster than FFT for large grids.
Browser only — silently falls back to a console warning in Node.
GPU context and shaders are lazily created and cached on the gridmodel.
Parameters:
| Name | Type | Description |
|---|---|---|
gridmodel |
object | |
state |
string | |
kernelObj |
object | from makeGaussianKernel |
- Source:
get2DFromCanvas(canvas) → {2DArray}
Reconstruct a 2D array based on a canvas
Parameters:
| Name | Type | Description |
|---|---|---|
canvas |
canvas | HTML canvas element to convert to a 2D grid for Cacatoo |
- Source:
Returns:
Returns a 2D array (i.e. a grid) with the states
- Type
- 2DArray
hexToRGB(hex)
Convert hexadecimal to RGB
Parameters:
| Name | Type | Description |
|---|---|---|
hex |
String | string to convert to RGB |
- Source:
makeDiskKernel(radius) → {Object}
Build a flat disk (top-hat) kernel for use with castDiskFFT.
Cells within radius get value 1, cells outside get 0. NOT normalised.
This means castDiskFFT deposits exactly `amount` at EACH cell within the
disk around each source — not `amount` spread across the disk area.
That matches the typical biological interpretation: every cell within
range receives the full benefit from a nearby source cell.
Parameters:
| Name | Type | Description |
|---|---|---|
radius |
number | Disk radius in grid cells |
- Source:
Returns:
- Type
- Object
makeGaussianKernel(sigma_x, sigma_yopt) → {Object}
Build a normalised Gaussian kernel for use with both diffuseStatesFFT
and diffuseStateGPU. Returns one object with everything both methods need.
Build it once, pass it to either method.
Pass only sigma_x for isotropic (symmetric) diffusion.
Pass both for anisotropic: sigma_x = horizontal spread (x/columns),
sigma_y = vertical spread (y/rows).
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
sigma_x |
number | Horizontal spread in grid cells. | |
sigma_y |
number |
<optional> |
Vertical spread. Defaults to sigma_x. |
- Source:
Returns:
- Type
- Object
Example
sim.model.k = makeGaussianKernel(3) // symmetric
sim.model.k = makeGaussianKernel(8, 1) // wide in x, narrow in y
this.diffuseStatesFFT('signal', null, this.k) // FFT path
this.diffuseStateGPU('signal', null, this.k) // GPU path
nameToRGB(name)
Convert colour name to RGB
Parameters:
| Name | Type | Description |
|---|---|---|
name |
String | string to look up in the set of known colours (see below) |
- Source:
parseColours(cols)
Make sure all colours, even when of different types, are stored in the same format (RGB, as cacatoo uses internally)
Parameters:
| Name | Type | Description |
|---|---|---|
cols |
Array | array of strings, or [R,G,B]-arrays. Only strings are converted, other returned. |
- Source:
pause()
Below are a few global functions that are used by Simulation classes, but not a method of a Simulation instance per se
- Source:
random_colours()
A list of default colours if nothing is given by the user.
- Source:
shuffle(array, rng)
Randomly shuffle an array with custom RNG
Parameters:
| Name | Type | Description |
|---|---|---|
array |
Array | array to be shuffled |
rng |
MersenneTwister | MersenneTwister RNG |
- Source:
stringToRGB(string)
Convert colour string to RGB. Works for colour names ('red','blue' or other colours defined in cacatoo), but also for hexadecimal strings
Parameters:
| Name | Type | Description |
|---|---|---|
string |
String | string to convert to RGB |
- Source: