Constructor
new Path(p5, nodes, settingsopt, isClosedopt, boundsopt, fillColoropt, strokeColoropt, invertedFillColoropt, invertedStrokeColoropt)
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)
Insert a new Node object from outside of this class
Parameters:
Name | Type | Description |
---|---|---|
node |
object | Node object to insert |
addToHistory()
Take a snapshot of the current nodes by saving a dereferenced clone of them to the history array
applyAlignment(index)
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)
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)
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)
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)
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()
Draw this Path to the canvas using current object visibility settings
drawBounds()
Draw boundary shape(s)
drawCurrentEdges()
Draw the current edges (leading edge) of the path
drawCurrentNodes()
Draw circles for every node
drawEdges(nodes)
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()
Draw all previous edges of the path saved to history array
getConnectedNodes(index) → {object}
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}
Get the current state of the "invert mode" flag
Returns:
Current state of the "invert mode" flag
- Type
- boolean
getMidpointNode(node1, node2, fixedopt) → {object}
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}
Get the current state of "trace mode" flag
Returns:
Current state of "trace mode" flag
- Type
- boolean
injectNode()
Insert a new Node using the current injection method
injectNodeByCurvature()
Insert a new Node in an area where curvature is high
injectRandomNode()
Insert a new Node in a random location along the Path, if there is space for it
iterate(tree)
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)
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()
Remove Nodes that are too close to their neighbors to minimize "pinching"
scale(factor)
Scale (multiply) all Nodes by the provided factor
Parameters:
Name | Type | Description |
---|---|---|
factor |
number | Factor to multiple all Nodes' coordinates by |
setBounds(bounds)
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)
Sets the state of the "invert mode" flag
Parameters:
Name | Type | Description |
---|---|---|
state |
boolean | New state for "invert mode" flag |
setMaxDistance(maxDistance)
Sets the maximum distance an edge can be before it is split
Parameters:
Name | Type | Description |
---|---|---|
maxDistance |
number |
setMinDistance(minDistance)
Sets the minimum distance that each Node wants to be from it's neighboring Nodes
Parameters:
Name | Type | Description |
---|---|---|
minDistance |
number |
setRepulsionRadius(repulsionRadius)
Sets the radius around each Node that it can affect other Nodes
Parameters:
Name | Type | Description |
---|---|---|
repulsionRadius |
number |
setTraceMode(state)
Sets the state of the "trace mode" flag
Parameters:
Name | Type | Description |
---|---|---|
state |
boolean | New state for "trace mode" flag |
splitEdges()
Search for edges that are too long and inject a new Node to split them up
toArray() → {array}
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()
Toggle the current state of the "invert mode" flag
toggleTraceMode()
Toggle the current state of the "trace mode" flag