World

World~ World

Manages a set of Paths and provides some global control mechanisms, such as pausing the simulation.

Constructor

new World(p5, settingsopt, pathsopt)

Source:
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)

Source:
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)

Source:
Add multiple Path objects to this World
Parameters:
Name Type Description
paths array

addToHistory()

Source:
Add another snapshot to each Path

buildTree()

Source:
Build an R-tree spatial index with all Nodes of all Paths in this World

clearPaths()

Source:
Remove all Paths from this World

createPathElFromNodes(nodes, isClosed)

Source:
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()

Source:
Draw the background and all Paths

drawBackground()

Source:
Draw the background to the canvas

export()

Source:
Generate an SVG file using the current canvas contents and open up a download prompt on the user's machine

getDebugMode() → {boolean}

Source:
Get the current state of the debug mode flag
Returns:
Current state of debug mode flag
Type
boolean

getDrawBounds() → {boolean}

Source:
Get the current state of the Bounds visibility flag
Returns:
Current state of the Bounds visibility flag
Type
boolean

getDrawHistory() → {boolean}

Source:
Get the current state of the history effect visibility flag
Returns:
Current state of the history effect visibility flag
Type
boolean

getDrawNodes() → {boolean}

Source:
Get the current state of the Nodes visibility flag
Returns:
Current state of Node visibility flag
Type
boolean

getFillMode() → {boolean}

Source:
Get the current state of the fill mode flag
Returns:
Current state of the fill mode flag
Type
boolean

iterate()

Source:
Run a single "tick" of the simulation by iterating on all Paths

pause()

Source:
Pause the simulation

prunePaths()

Source:
Remove any Paths that have gotten too small

setAlignmentForce(alignmentForce)

Source:
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)

Source:
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)

Source:
Set the state of the "debug mode" flag
Parameters:
Name Type Description
state boolean Next state for the "debug mode" flag

setDrawBounds(state)

Source:
Set the state of the Bounds visibility flag
Parameters:
Name Type Description
state boolean Next state for the Bounds visibility flag

setDrawHistory(state)

Source:
Set the state of the "history" effect flag
Parameters:
Name Type Description
state boolean Next state for the "history" effect flag

setDrawNodes(state)

Source:
Set the state of the Node visibility flag
Parameters:
Name Type Description
state boolean Next state for the Node visibility flag

setFillMode(state)

Source:
Set the state of the "fill mode" flag
Parameters:
Name Type Description
state boolean Next state for the "fill mode" flag

setInvertedColors(state)

Source:
Set the state of the "invert colors" flag
Parameters:
Name Type Description
state boolean Next state for the "invert colors" flag

setMaxDistance(maxDistance)

Source:
Set the maximum distance an edge can be before it is split
Parameters:
Name Type Description
maxDistance number Distance between each Node

setMinDistance(minDistance)

Source:
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)

Source:
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)

Source:
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)

Source:
Set the state of the "trace mode" flag
Parameters:
Name Type Description
state boolean Next state for the "trace mode" flag

toggleDebugMode()

Source:
Toggle the state of the "debug mode" flag

toggleDrawBounds()

Source:
Toggle the state of the Bounds visibility flag

toggleDrawHistory()

Source:
Toggle the state of the "history" effect flag

toggleDrawNodes()

Source:
Toggle the state of the Node visibility flag

toggleFillMode()

Source:
Toggle the state of the "fill mode" flag

toggleInvertedColors()

Source:
Toggle the state of the "invert colors" flag

togglePause()

Source:
Toggle the pause/unpause state of the simulation

toggleTraceMode()

Source:
Toggle the state of the "trace mode" effect flag

unpause()

Source:
Unpause the simulation