Class: InertialEngine

core.InertialEngine

Class representing an engine for simulating the physics of inertial motion in up to three dimensions.

The engine works by taking samples of a motion repeatedly with the method core.InertialEngine#takeSample and then applying the friction with the method core.InertialEngine#start.

new core.InertialEngine ()

Properties:
Name Type Description
friction number

(default: 0.08) The friction coefficient. A friction of 0 lets the inertial motion continue forever, while a friction of 1 allows no inertial motion.

running bool

[readonly] If the engine is currently running.

Extends

Methods

reset (x, y, z)

Resets the engine to the given initial coordinates.

Name Type Default Description
x number

The X coordinate.

y number 0 optional

The Y coordinate.

z number 0 optional

The Z coordinate.

start () async

Starts the engine. This will emit a series of motion events until the friction stopped the motion.

Stops the engine abruptly.

takeSample (x, y, z)

Takes a sample with the given coordinates.

Name Type Default Description
x number

The X coordinate.

y number 0 optional

The Y coordinate.

z number 0 optional

The Z coordinate.

Events

core.InertialEngine.event:motion

Is triggered when a motion shall occur. This event is also emitted while taking samples.

Name Type Description
dx number

The motion in X direction.

dy number

The motion in Y direction.

dz number

The motion in Z direction.