Constructor
new (require("DLA"))(p5, settings)
Create a new DLA object with reference to global P5 instance and any local sketch Settings
Parameters:
Name | Type | Description |
---|---|---|
p5 |
object | Global p5.js instance passed from main sketch |
settings |
object | Object containing any override values passed from sketch to be merged with global Defaults |
Methods
createCircleElFromBody(body) → {node}
Create an SVG element with attributes `cx`, `cy`, and `r` extracted from provided body
Parameters:
Name | Type | Description |
---|---|---|
body |
object |
Returns:
SVG element with `cx`, `cy`, and `r` attributes from body
- Type
- node
createClusterFromParams(paramsList)
Create a set of clustered particles from an array of individual particle parameters
Parameters:
Name | Type | Description |
---|---|---|
paramsList |
Array | Array of objects containing particle parameters. |
createDefaultClusters(clusterType)
Create a set of clustered particles with the provided pattern.
Parameters:
Name | Type | Description |
---|---|---|
clusterType |
string | Pattern to create all clustered particles with. Can be Point, Ring, Random, or Wall |
createDefaultWalkers(count, source)
Create a set of walkers in a specific area in the simulation (center, edges, randomly, etc).
Parameters:
Name | Type | Description |
---|---|---|
count |
number | Number of walkers to create |
source |
string | Location where walkers should be created. |
createHorizontalClusterWall(yPos) → {Object}
Create a horizontal line of clustered particles at a given Y coordinate
Parameters:
Name | Type | Description |
---|---|---|
yPos |
number | vertical coordinate where line of particles is created |
Returns:
Object containing X and Y coordinates of all clustered particles in line
- Type
- Object
createParticle(params)
Creates a new body (walker or clustered particle) using the provided parameters in the collision system and stores it in a private array for manipulation later.
Parameters:
Name | Type | Description |
---|---|---|
params |
object | Object of particle parameters such as X/Y coordinates, type, shape, and rotation |
createPathElFromPoints(points) → {node}
Create a element with a "d" attribute containing provided points
Parameters:
Name | Type | Description |
---|---|---|
points |
array |
Returns:
SVG element with "d" attribute containing provided points
- Type
- node
createShapesFromPaths(paths)
Create shapes in the internal collision detection system from a set of paths
Parameters:
Name | Type | Description |
---|---|---|
paths |
Array | Array of objects defining polygons (technically polylines) with starting X and Y coordinates and a list of points |
createVerticalClusterWall(xPos) → {Object}
Create a vertical line of clustered particles at a given X coordinate
Parameters:
Name | Type | Description |
---|---|---|
xPos |
number | horizontal coordinate where line of particles is created |
Returns:
Object containing the X and Y coordinates of all clustered particles in line
- Type
- Object
createWalker(params)
Wrapper for createParticle() that increments internal count of walkers.
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Object of particle parameters such as X/Y coordinates, type, shape, and rotation |
draw()
Draw all objects based on current visibility flags and colors
drawFrame()
Draw a rectangle to represent the frame (bounding box), if active
export()
Constructs an SVG node with paths based on current rendering mode of the simulation, then initiates a download on the user's machine of the generated file
getColorStringFromObject(colorObject) → {string}
Create an HSL-formatted string that plays well with p5.js from an object with appropriate properties
Parameters:
Name | Type | Description |
---|---|---|
colorObject |
object | Object with the properties h, s, and b (all numbers) |
Returns:
- String in the format of hsl({h}, {s}, {b})
- Type
- string
getDeltasTowards(bodyX, bodyY, targetX, targetY) → {Object}
Calculates movement deltas for a given walker in order to move it towards a given point in space.
Parameters:
Name | Type | Description |
---|---|---|
bodyX |
number | X coordinate of walker to move |
bodyY |
number | Y coordinate of walker to move |
targetX |
number | X coordinate of target we want to move the walker towards |
targetY |
number | YY coordinate of target we want to move the walker towards |
Returns:
Object with properties x and y representing directional forces to apply to walker
- Type
- Object
getPointsFromCoords(coords)
Convert a flat array of coords ([x1, y1, x2, y2, ...]), used internally by collisions package into an array of objects for easier traversing
Parameters:
Name | Type | Description |
---|---|---|
coords |
array |
handleCollisions()
Look for collisions between walkers and clustered elements, converting walkers to clustered particles as needed.
iterate()
Run one "tick" of the simulation
moveWalkers()
Apply Brownian motion and bias forces to all walkers to make them move a little bit.
pause()
Pause the simulation
pruneWalkers()
Remove any walkers that are no longer "useful" in an effort to make the simulation more efficient.
removeAll()
Remove all walkers, clustered particles, shapes, and lines from the system
resetEdges()
Recalculate the positions of the four edges of the simulation based on whether the frame is in use or not.
toggleLineRenderingMode()
Toggle the line-based rendering mode
togglePause()
Toggle between paused or unpaused state
toggleShowClusters()
Toggle the visibility of clustered particles
toggleShowShapes()
Toggle the visibility of shapes
toggleShowWalkers()
Toggle the visibility of walkers
toggleUseFrame()
Toggle the use of a custom-defined frame (bounding box)
unpause()
Unpause the simulation