controllerSpring
spring(strength, max_len,
fixed_point_id, paths)
spring.messages = []
spring.events = []
Description
Simulates an attracting (or repulsing) 'spring' force that accelerates the element towards another target element
or towards a path made of one or several move()
controllers.
Acceleration is proportional to the distance to the target.
If parameter max_len
is supplied, then the force becomes very strong when the distance to the target reaches this value,
effectively limiting the maximal length/'stretching' of the 'spring'.
Note that since the algorithm is not precise (that's not the point of behave3d),
this controller tends to accelerate the element more and more when passing close to the target even if it's not moving.
This over-acceleration can be tampered with the use of the slow()
controller.
The physics simulation applies one translate
transform.
Parameters
Visit page Controller # Common Parameters for documentation on the parameters, common to all controllers:
id
,
paused
and
disabled
.
Parameters of spring()
:
- strength
- Strength of force. Larger value results in faster acceleration. Note that negative values are posible, which will make the force repulsing instead of attracting. Default value: 1
- max_len
-
Maximal length of the 'spring' in pixels, or
0
for unlimited spring length. Default value: 0 - fixed_point_id
-
DOM ID of the target element to which the force attracts if no
paths
are specified. If both parametersfixed_point_id
andpaths
are not supplied, then the element will be attracted to its initial position. Default value: "" - paths
-
A space-delimited list of controller
id
s ofmove()
controllers belonging to this element. The sum of these controllers' current coordinates makes the coordinates of the spring's target. Default value: ""
Accepted Messages
Visit page Controller # Common Messages for documentation on the messages, accepted by all controllers:
pause
,
unpause
,
enable
,
disable
,
params
and
remove
.
Messages specific to spring()
: none
Generated Events
Visit page Controller # Common Events for documentation on the events, generated by all controllers:
frame
,
remove
,
paused
,
unpaused
enabled
and
disabled
.
Events specific to spring()
: none
Interaction with DOM
- Transforms: The physics engine applies one
translate
transform. - CSS: Works with any styling. Does not set any style properties.
- Events: Does not set event listeners.
Changes Log
- Controller introduced in v.0.80