Class: Spring

Spring(position, k, m, lengthOfSpring, oscAmp, mu)

new Spring(position, k, m, lengthOfSpring, oscAmp, mu)

Creates a Spring object. Consists of a spring with a block attached to the end.
Parameters:
Name Type Description
position p5.Vector The origin of the Spring.
k number Spring coefficient.
m number Mass of the block attached to the spring.
lengthOfSpring number Length of the Spring in px.
oscAmp number Amplitude of the oscillation.
mu number Coefficient of friction.
Properties:
Name Type Description
boxSize number Length of the sides of the box attached to spring.
lengthOfSpring number The current length of the spring in pixels.
noOfCoils number The number of coils. Decorative. Odd numbers work best. (default: 11)
transAmp number Transverse amplitude. Decorative. (default: 15)
tZero number The start time in milliseconds.
t number Time. (default: 0)
playing bool Controls the state of the simulation.
xCent number x-coord for the center of the spring.
yCent number y-coord for the center of the spring.
rotation radian Angle of orientation. Use 0 for a horizontal spring, and PI/2 for a vertical one.
oscamp number The oscillation amplitude as a fraction of the lengthOfSpring. A value of 0.2 is recommended as it will be 1/5 the length of the spring.
freq number Calculates the frequency based on the spring constant k and the mass of the block m.
equilibrium p5.Vector The equilibrium point.
displacement p5.Vector The magnitude of displacement.
velocity p5.Vector The velocity.
acceleration p5.Vector The acceleration.
Spring.update() method Updates the Spring object.
Spring.display() method Displays the Spring object.
Source: