module:DLA

module:DLA

Structure for managing state and properties of all walkers, clusters, shapes, and the collision system.

Constructor

new (require("DLA"))(p5, settings)

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

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

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

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

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}

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

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

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

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

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

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

Source:
Draw all objects based on current visibility flags and colors

drawFrame()

Source:
Draw a rectangle to represent the frame (bounding box), if active

export()

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

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

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

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

Source:
Look for collisions between walkers and clustered elements, converting walkers to clustered particles as needed.

iterate()

Source:
Run one "tick" of the simulation

moveWalkers()

Source:
Apply Brownian motion and bias forces to all walkers to make them move a little bit.

pause()

Source:
Pause the simulation

pruneWalkers()

Source:
Remove any walkers that are no longer "useful" in an effort to make the simulation more efficient.

removeAll()

Source:
Remove all walkers, clustered particles, shapes, and lines from the system

resetEdges()

Source:
Recalculate the positions of the four edges of the simulation based on whether the frame is in use or not.

toggleLineRenderingMode()

Source:
Toggle the line-based rendering mode

togglePause()

Source:
Toggle between paused or unpaused state

toggleShowClusters()

Source:
Toggle the visibility of clustered particles

toggleShowShapes()

Source:
Toggle the visibility of shapes

toggleShowWalkers()

Source:
Toggle the visibility of walkers

toggleUseFrame()

Source:
Toggle the use of a custom-defined frame (bounding box)

unpause()

Source:
Unpause the simulation