Path

Path~ Path

Manages a set of Nodes in a continuous, ordered data structure (an Array).

Constructor

new Path(p5, nodes, settingsopt, isClosedopt, boundsopt, fillColoropt, strokeColoropt, invertedFillColoropt, invertedStrokeColoropt)

Source:
Create a new Path object
Parameters:
Name Type Attributes Default Description
p5 object Reference to global p5.js instance
nodes array Array of initial Node objects to start with
settings object <optional>
Object containing local override Settings to be merged with Defaults
isClosed boolean <optional>
false Whether this Path is closed (true) or open (false)
bounds object <optional>
false Bounds object that this Path must stay within
fillColor object <optional>
Fill color object containing properties h, s, b, and a
strokeColor object <optional>
Stroke color object containing properties h, s, b, and a
invertedFillColor object <optional>
Fill color in "invert mode" containing properties h, s, b, and a
invertedStrokeColor object <optional>
Stroke color in "invert mode" containing properties h, s, b, and a

Methods

addNode(node)

Source:
Insert a new Node object from outside of this class
Parameters:
Name Type Description
node object Node object to insert

addToHistory()

Source:
Take a snapshot of the current nodes by saving a dereferenced clone of them to the history array

applyAlignment(index)

Source:
Move the referenced Node (by index) towards the midpoint of it's connected neighbor Nodes in an effort to minimize curvature
Parameters:
Name Type Description
index number Index of Node to apply forces to

applyAttraction(index)

Source:
Move the Node with the provided index closer to it's connected neighbor Nodes
Parameters:
Name Type Description
index number Index of Node to apply forces to

applyBounds(index)

Source:
Do not allow the referenced Node (by index) to leave the interior of the assigned Bounds polygon
Parameters:
Name Type Description
index number Index of Node to apply force to

applyBrownianMotion(index)

Source:
For the Node wit the provided index, simulate the small random motions that real microscopic particles experience from collisions with fast-moving molecules
Parameters:
Name Type Description
index number Index of Node to apply forces to

applyRepulsion(index, tree)

Source:
Move the referenced Node (by index) away from all other nearby Nodes within the appropriate R-tree index (tree), within a pre-defined radius
Parameters:
Name Type Description
index number Index of Node to apply forces to
tree object Reference to the appropriate R-tree index that this Path belongs to (see World)

draw()

Source:
Draw this Path to the canvas using current object visibility settings

drawBounds()

Source:
Draw boundary shape(s)

drawCurrentEdges()

Source:
Draw the current edges (leading edge) of the path

drawCurrentNodes()

Source:
Draw circles for every node

drawEdges(nodes)

Source:
Draw edges for a given set of nodes - can be either the current or previous nodes
Parameters:
Name Type Description
nodes array Array of Node objects

drawPreviousEdges()

Source:
Draw all previous edges of the path saved to history array

getConnectedNodes(index) → {object}

Source:
For a given Node, find a return it's immediate connected neighbor Nodes
Parameters:
Name Type Description
index number Index of Node to retrieve neighbors of
Returns:
References to previous and next nodes, if they exist. Will always return a value for at least one.
Type
object

getInvertedColors() → {boolean}

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

getMidpointNode(node1, node2, fixedopt) → {object}

Source:
Create and return a Node exactly halfway between the two provided Nodes
Parameters:
Name Type Attributes Default Description
node1 object First node
node2 object Second node
fixed boolean <optional>
false Whether this new Node should be fixed or not
Returns:
New Node object
Type
object

getTraceMode() → {boolean}

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

injectNode()

Source:
Insert a new Node using the current injection method

injectNodeByCurvature()

Source:
Insert a new Node in an area where curvature is high

injectRandomNode()

Source:
Insert a new Node in a random location along the Path, if there is space for it

iterate(tree)

Source:
Run one "tick" of the simulation
Parameters:
Name Type Description
tree object Reference to the appropriate R-tree index that this Path belongs to (see World)

moveTo(xOffset, yOffset)

Source:
Move this entire Path by a certain amount by moving all of it's Nodes
Parameters:
Name Type Description
xOffset number Distance on X axis to move Path
yOffset number Distance on Y axis to move Path

pruneNodes()

Source:
Remove Nodes that are too close to their neighbors to minimize "pinching"

scale(factor)

Source:
Scale (multiply) all Nodes by the provided factor
Parameters:
Name Type Description
factor number Factor to multiple all Nodes' coordinates by

setBounds(bounds)

Source:
Set the Bounds object that this Path must stay within
Parameters:
Name Type Description
bounds object Bounds object that this Path must stay within

setInvertedColors(state)

Source:
Sets the state of the "invert mode" flag
Parameters:
Name Type Description
state boolean New state for "invert mode" flag

setMaxDistance(maxDistance)

Source:
Sets the maximum distance an edge can be before it is split
Parameters:
Name Type Description
maxDistance number

setMinDistance(minDistance)

Source:
Sets the minimum distance that each Node wants to be from it's neighboring Nodes
Parameters:
Name Type Description
minDistance number

setRepulsionRadius(repulsionRadius)

Source:
Sets the radius around each Node that it can affect other Nodes
Parameters:
Name Type Description
repulsionRadius number

setTraceMode(state)

Source:
Sets the state of the "trace mode" flag
Parameters:
Name Type Description
state boolean New state for "trace mode" flag

splitEdges()

Source:
Search for edges that are too long and inject a new Node to split them up

toArray() → {array}

Source:
Return a raw 2D array of all Node coordinates. Useful for creating Bounds objects.
Returns:
Array of all Node coordinates in the format of [polygon_n][x1][y1], ...
Type
array

toggleInvertedColors()

Source:
Toggle the current state of the "invert mode" flag

toggleTraceMode()

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