Class: Field

Field(width, height)

A class representing an electrostatic field and all the particles that create it.

Constructor

new Field(width, height)

Create a Field
Parameters:
Name Type Description
width number The width of the Field
height number The height of the Field
Source:

Members

field :Array.<Array.<p5.Vector>>

2D field vector array.
Type:
  • Array.<Array.<p5.Vector>>
Source:

particles :Particle

Particles stack.
Type:
Source:

Methods

addParticle(part)

Adds a particle to the field particles stack. Calculates the new field vectors.
Parameters:
Name Type Description
part Particle The particle to be added to the field.
Source:

clear()

Empties the particle stack. Zeros the field using Field#zeroField
Source:

draw(space, scale)

Draws the field vectors. Draws the particles creating the field.
Parameters:
Name Type Description
space number The distance in pixels between each grid point.
scale number A scale factor that shortens or lengthens the field vectors that are drawn.
Source:

popParticle()

Pops particle from the fields particles stack. Recalculates the field with the particle gone.
Source:

zeroField() → {Array.<Array.<p5.Vector>>}

Creates field array where all values are a zero vector.
Source:
Returns:
The 2D array containing the zero field vectors.
Type
Array.<Array.<p5.Vector>>

Documentation generated by JSDoc 4.0.2 on Sun Jan 26 2025 19:14:19 GMT-0800 (Pacific Standard Time)