pex-physics-springs
Simple springs physics for Pex library, working with floats, Vec2, and Vec3.
Examples
For use with simple float numbers:
var Window = Window;var Platform = Platform;var Canvas = ; var Spring = Spring; Window;
For use with Vec2:
var Window = Window;var Platform = Platform;var Vec2 = Vec2;var Canvas = ; var Spring2 = Spring2; Window;
Methods
Spring(position, stiffness, friction, threshold, dt)
Constructor for spring, arguments:
position
- initial spring position (float
/Vec2
/Vec3
) depending on (Spring
/Spring2
/Spring3
)stiffness
- spring stiffnessfriction
- spring frictionthreshold
- spring thresholddt
- time coefficient, usually1/30
or1/60
setPosition(position)
Resets spring positions, arguments:
position
- new default and current spring position
setTarget(position)
Sets spring target, arguments:
position
- spring "target", changing this will result in "springiness", if set tonull
the spring will default to initial position
getPosition()
Returns current spring position.
getDefault()
Returns default (initial) spring position.
update()
Updates spring calculation, should be run in every draw()
in Pex.