Quick search

Table Of Contents

Kinetic effect

New in version 1.7.0.

The KineticEffect is the base class that is used to compute the velocity out of a movement. When the movement is finished, the effect will compute the position of the movement according to the velocity, and reduce the velocity with a friction. The movement stop until the velocity is 0.

Conceptually, the usage could be:

>>> effect = KineticEffect()
>>> effect.start(10)
>>> effect.update(15)
>>> effect.update(30)
>>> effect.stop(48)

Over the time, you will start a movement of a value, update it, and stop the movement. At this time, you’ll get the movement value into KineticEffect.value. On the example i’ve typed manually, the computed velocity will be:

>>> effect.velocity
3.1619100231163046

After multiple clock interaction, the velocity will decrease according to KineticEffect.friction. The computed value will be stored in KineticEffect.value. The output of this value could be:

46.30038145219605
54.58302451968686
61.9229016256196
# ...
class kivy.effects.kinetic.KineticEffect(**kwargs)

Bases: kivy.event.EventDispatcher

Kinetic effect class. See module documentation for more information.

cancel()

Cancel a movement. This can be used in case of stop() cannot be called. It will reset is_manual to False, and compute the movement if the velocity is > 0.

friction

Friction to apply on the velocity

velocity is a NumericProperty, default to 0.05

is_manual

Indicate if a movement is in progress (True) or not (False).

velocity is a BooleanProperty, default to False

max_history

Save up to max_history movement value into the history. This is used for correctly calculating the velocity according to the movement.

max_history is a NumericProperty, default to 5.

start(val, t=None)

Start the movement.

Parameters :
val: float or int

Value of the movement

t: float, default to None

Time when the movement happen. If no time is set, it will use time.time()

stop(val, t=None)

Stop the movement.

See start() for the arguments.

update(val, t=None)

Update the movement.

See start() for the arguments.

update_velocity(dt)

(internal) Update the velocity according to a frametime and the friction.

value

Value (during the movement and computed) of the effect.

velocity is a NumericProperty, default to 0

velocity

Velocity of the movement.

velocity is a NumericProperty, default to 0