Advanced
Easings
Easings describe how a value moves from 0 to 1 across a time range.
from margrete_rpc.chart.util import Curve, timing_easing
slide = Curve(t=(0, 0), x=0).to(t=(1, 0), x=12, ease_x="in_out_sine").to_slide(w=4)
speed_events = timing_easing(
t0=(4, 0),
t1=(8, 0),
start_speed=0.5,
end_speed=2.0,
count=16,
easing="out_cubic",
)Which name to use
Each easing family has three directions:
| Direction | Meaning |
|---|---|
in_* | Starts slowly and changes more near the end. |
out_* | Changes quickly first and slows near the end. |
in_out_* | Starts slowly, moves faster in the middle, then slows again. |
Common choices:
| Name | Good for |
|---|---|
linear | Constant movement or equal speed steps. |
in_quad | A simple acceleration into the target. |
out_quad | A simple deceleration into the target. |
in_out_sine | Smooth, natural movement between two points. |
out_cubic | A stronger ease-out than out_quad. |
in_out_expo | A dramatic slow-fast-slow movement. |
Built-in names
| Family | Names |
|---|---|
| Linear | linear |
| Sine | in_sine, out_sine, in_out_sine |
| Quad | in_quad, out_quad, in_out_quad |
| Cubic | in_cubic, out_cubic, in_out_cubic |
| Quart | in_quart, out_quart, in_out_quart |
| Quint | in_quint, out_quint, in_out_quint |
| Expo | in_expo, out_expo, in_out_expo |
| Circ | in_circ, out_circ, in_out_circ |
Custom easings
Anywhere an easing name is accepted, you can also pass an Easing
object or a callable from 0..1 to 0..1.
import math
from margrete_rpc.chart.util import Curve
def stepped_4(t: float) -> float:
return math.floor(t * 4) / 4 if t < 1 else 1.0
slide = (
Curve(t=(0, 0), x=0)
.to(t=(1, 0), x=12, ease_x=stepped_4)
.to_slide(w=4)
)Custom easings should usually return 0 at input 0 and 1 at input 1. That keeps generated curves and
speed ramps landing exactly on their start and end values.