Constructor
new World(p5, settingsopt, pathsopt)
Create a new World object
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
p5 |
object | Reference to global p5.js instance | |
settings |
object |
<optional> |
Object containing local override Settings to be merged with Defaults |
paths |
array |
<optional> |
Array of Path objects that belong to this World |
Methods
addPath(path)
Add a new Path to the World from outside this class
Parameters:
Name | Type | Description |
---|---|---|
path |
object | Path object to add to this World |
addPaths(paths)
Add multiple Path objects to this World
Parameters:
Name | Type | Description |
---|---|---|
paths |
array |
addToHistory()
Add another snapshot to each Path
buildTree()
Build an R-tree spatial index with all Nodes of all Paths in this World
clearPaths()
Remove all Paths from this World
createPathElFromNodes(nodes, isClosed)
Create a new SVG path element from a provided set of Node objects
Parameters:
Name | Type | Description |
---|---|---|
nodes |
array | Array of Node objects |
isClosed |
boolean | Whether this path should be closed (true) or open (false) |
Returns:
SVG path DOM node with a `d` attribute generated from the provided Nodes array.
draw()
Draw the background and all Paths
drawBackground()
Draw the background to the canvas
export()
Generate an SVG file using the current canvas contents and open up a download prompt on the user's machine
getDebugMode() → {boolean}
Get the current state of the debug mode flag
Returns:
Current state of debug mode flag
- Type
- boolean
getDrawBounds() → {boolean}
Get the current state of the Bounds visibility flag
Returns:
Current state of the Bounds visibility flag
- Type
- boolean
getDrawHistory() → {boolean}
Get the current state of the history effect visibility flag
Returns:
Current state of the history effect visibility flag
- Type
- boolean
getDrawNodes() → {boolean}
Get the current state of the Nodes visibility flag
Returns:
Current state of Node visibility flag
- Type
- boolean
getFillMode() → {boolean}
Get the current state of the fill mode flag
Returns:
Current state of the fill mode flag
- Type
- boolean
iterate()
Run a single "tick" of the simulation by iterating on all Paths
pause()
Pause the simulation
prunePaths()
Remove any Paths that have gotten too small
setAlignmentForce(alignmentForce)
Set the force scalar that is used when Nodes trying to align with their neighbors to reduce curvature
Parameters:
Name | Type | Description |
---|---|---|
alignmentForce |
number | Scalar value used for alignment force |
setAttractionForce(attractionForce)
Set the force scalar that is used when Nodes pull each other closer
Parameters:
Name | Type | Description |
---|---|---|
attractionForce |
number | Scalar value used for attraction force |
setDebugMode(state)
Set the state of the "debug mode" flag
Parameters:
Name | Type | Description |
---|---|---|
state |
boolean | Next state for the "debug mode" flag |
setDrawBounds(state)
Set the state of the Bounds visibility flag
Parameters:
Name | Type | Description |
---|---|---|
state |
boolean | Next state for the Bounds visibility flag |
setDrawHistory(state)
Set the state of the "history" effect flag
Parameters:
Name | Type | Description |
---|---|---|
state |
boolean | Next state for the "history" effect flag |
setDrawNodes(state)
Set the state of the Node visibility flag
Parameters:
Name | Type | Description |
---|---|---|
state |
boolean | Next state for the Node visibility flag |
setFillMode(state)
Set the state of the "fill mode" flag
Parameters:
Name | Type | Description |
---|---|---|
state |
boolean | Next state for the "fill mode" flag |
setInvertedColors(state)
Set the state of the "invert colors" flag
Parameters:
Name | Type | Description |
---|---|---|
state |
boolean | Next state for the "invert colors" flag |
setMaxDistance(maxDistance)
Set the maximum distance an edge can be before it is split
Parameters:
Name | Type | Description |
---|---|---|
maxDistance |
number | Distance between each Node |
setMinDistance(minDistance)
Set the minimum distance that each Node wants to be from it's connected neighbors
Parameters:
Name | Type | Description |
---|---|---|
minDistance |
number | Distance that each Node wants to be from it's neighbors |
setRepulsionForce(repulsionForce)
Set the force scalar that is used when Nodes are pushing others away
Parameters:
Name | Type | Description |
---|---|---|
repulsionForce |
number | Scalar value used for repulsion force |
setRepulsionRadius(repulsionRadius)
Set the distance around each Node that it can affect other Nodes through repulsion
Parameters:
Name | Type | Description |
---|---|---|
repulsionRadius |
number | Distance around each Node |
setTraceMode(state)
Set the state of the "trace mode" flag
Parameters:
Name | Type | Description |
---|---|---|
state |
boolean | Next state for the "trace mode" flag |
toggleDebugMode()
Toggle the state of the "debug mode" flag
toggleDrawBounds()
Toggle the state of the Bounds visibility flag
toggleDrawHistory()
Toggle the state of the "history" effect flag
toggleDrawNodes()
Toggle the state of the Node visibility flag
toggleFillMode()
Toggle the state of the "fill mode" flag
toggleInvertedColors()
Toggle the state of the "invert colors" flag
togglePause()
Toggle the pause/unpause state of the simulation
toggleTraceMode()
Toggle the state of the "trace mode" effect flag
unpause()
Unpause the simulation