Skip to content

LinearRamp

Slide a value smoothly from one number to another over time, calling a function as it changes.

linearramp = LinearRamp(delay, startValue, endValue, action)

A LinearRamp moves a value from a start to an end over a set time, calling your function with the current value at each small step along the way. This is handy for fading volume, moving graphics, and other gradual changes. Start it with start(), and aim it somewhere new with setTarget() while it runs.

Creating a LinearRamp

LinearRamp(delay, startValue, endValue, action, step=10)

You can create a LinearRamp with the following parameters:

Parameter Type Default Description
delay int or float required How long the whole ramp takes, in milliseconds.
startValue int or float required The value to start from.
endValue int or float required The value to end at.
action function required The function to call as the value changes; it receives one parameter, the current value.
step int 10 How often to update the value and call the function, in milliseconds.

Functions

Once a LinearRamp linearramp has been created, the following functions are available:

Function Description
linearramp.start() Start the ramp from its current value toward its target.
linearramp.stop() Stop the ramp where it is.
linearramp.setTarget(targetValue) Aim the ramp at a new value, starting from where it is now.
linearramp.setDuration(delay) Change how long the ramp takes.
linearramp.isRunning() Report whether the ramp is running.
linearramp.getCurrentValue() Return the ramp's current value.