Animation¶
keyed.animation
¶
Animation related classes/functions.
AnimationType
¶
Bases: Enum
Specifies the mathematical operation used to combine the original and animated values.
Source code in src/keyed/animation.py
Animation
¶
Bases: Generic[T]
Define an animation.
Animations vary a parameter over time.
Generally, Animations become active at start_frame and smoothly change
according to the easing function until terminating to a final value at
end_frame. The animation will remain active (i.e., the parameter will
not suddenly jump back to it's pre-animation state), but will cease varying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
int
|
Frame at which the animation will become active. |
required |
end
|
int
|
Frame at which the animation will stop varying. |
required |
start_value
|
HasValue[T]
|
Value at which the animation will start. |
required |
end_value
|
HasValue[T]
|
Value at which the animation will end. |
required |
ease
|
EasingFunctionT
|
The rate in which the value will change throughout the animation. |
linear_in_out
|
animation_type
|
AnimationType
|
How the animation value will affect the original value. |
ABSOLUTE
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in src/keyed/animation.py
Loop
¶
Bases: Animation[T], Generic[T]
Loop an animation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animation
|
Animation[T]
|
The animation to loop. |
required |
n
|
int
|
Number of times to loop the animation. |
1
|
Source code in src/keyed/animation.py
PingPong
¶
Bases: Animation[T], Generic[T]
Play an animation forward, then backwards n times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animation
|
Animation[T]
|
The animation to ping-pong. |
required |
n
|
int
|
Number of full back-and-forth cycles |
1
|
Source code in src/keyed/animation.py
end_frame
property
¶
Returns the frame at which the animation stops varying.
Notes
Each cycle consists of going forward and coming back.
stagger
¶
stagger(start_value=0, end_value=1, ease=linear_in_out, animation_type=ABSOLUTE)
Partially-initialize an animation for use with Group.write_on.
This will set the animations values, ease, and type without setting its start/end frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_value
|
float
|
Value at which the animation will start. |
0
|
end_value
|
float
|
Value at which the animation will end. |
1
|
ease
|
EasingFunctionT
|
The rate in which the value will change throughout the animation. |
linear_in_out
|
animation_type
|
AnimationType
|
How the animation value will affect the original value. |
ABSOLUTE
|
Returns:
| Type | Description |
|---|---|
partial[Animation]
|
Partially initialized animation. |
Source code in src/keyed/animation.py
step
¶
Return an animation that applies a step function to the Variable at a particular frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
HasValue[T]
|
The value to step to. |
required |
frame
|
int
|
The frame at which the step will be applied. |
ALWAYS
|
animation_type
|
AnimationType
|
See :class: |
ABSOLUTE
|
Returns:
| Type | Description |
|---|---|
Animation[T]
|
An animation that applies a step function to the Variable at a particular frame. |
Source code in src/keyed/animation.py
Builders¶
keyed.builders
¶
Builder APIs for animated values on a timeline.
Cues, Flow, and
Keys all compile to the same underlying
Animation chain. They differ only in the
timing vocabulary they expose:
Cuesplaces transitions by absolute start frame.Flowdescribes a forward-only relative sequence.Keysplaces absolute points where values arrive.
Cues
¶
Bases: Generic[T]
Build an animation from absolute transition cues.
Each at call names the frame where a transition
starts, its target value, and how long it should run. Between cues, the
value holds at the previous cue's target.
Use this builder when your timing is already expressed in absolute frames,
or when you want to insert transitions out of order and let
build sort them chronologically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial
|
HasValue[T]
|
The value before any cues are reached. |
required |
Examples:
from keyed import Color, easing
from keyed.builders import Cues
black = Color(0, 0, 0)
yellow = Color(0.75, 0.75, 0)
x_color = (
Cues(black)
.at(120, yellow, over=12, ease=easing.cubic_in_out)
.at(156, black, over=12)
.build()
)
Source code in src/keyed/builders.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
at
¶
at(frame, to, over=0, ease=linear_in_out, animation_type=ABSOLUTE)
Add a cue: start transitioning to to at frame frame over over frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
int
|
Frame at which the transition begins. |
required |
to
|
HasValue[T]
|
Target value. |
required |
over
|
int
|
Duration of the transition in frames. |
0
|
ease
|
EasingFunctionT
|
Easing function. |
linear_in_out
|
animation_type
|
AnimationType
|
How to combine with the base value. |
ABSOLUTE
|
Source code in src/keyed/builders.py
snap
¶
snap(frame, to, animation_type=ABSOLUTE)
Add an instant snap to to at frame frame.
Shorthand for .at(frame, to, over=0).
Source code in src/keyed/builders.py
build
¶
Build and return the reactive animation value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
ReactiveValue[int] | None
|
Frame signal to evaluate against. Defaults to the active Scene's frame. |
None
|
Source code in src/keyed/builders.py
Flow
¶
Bases: Generic[T]
Build an animation as a forward-only sequence of relative transitions.
tweenadds a smooth transition over a duration.holdadvances the cursor without animating.snapapplies an instant change at the current cursor.
The cursor starts at at and advances with each
tween and
hold call. After the optional initial anchor,
no absolute frame numbers appear in the method arguments.
Use this builder when you want to describe what happens next without doing frame arithmetic by hand.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
HasValue[T]
|
Initial value (before any transitions). |
required |
at
|
int
|
Starting frame for the first transition. Defaults to |
0
|
Examples:
from keyed import Color, easing
from keyed.builders import Flow
black = Color(0, 0, 0)
yellow = Color(0.75, 0.75, 0)
x_color = (
Flow(black, at=120)
.tween(12, yellow, ease=easing.cubic_in_out)
.hold(24)
.tween(12, black)
.build()
)
Source code in src/keyed/builders.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
tween
¶
tween(duration, to, ease=linear_in_out, animation_type=ABSOLUTE)
Smoothly animate to to over duration frames.
Advances the cursor by duration frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
int
|
Number of frames for the transition. |
required |
to
|
HasValue[T]
|
Target value. |
required |
ease
|
EasingFunctionT
|
Easing function. |
linear_in_out
|
animation_type
|
AnimationType
|
How to combine with the base value. |
ABSOLUTE
|
Source code in src/keyed/builders.py
hold
¶
snap
¶
snap(to, animation_type=ABSOLUTE)
Instantly snap to to at the current cursor. Cursor does not advance.
Shorthand for .tween(0, to).
Source code in src/keyed/builders.py
build
¶
Build and return the reactive animation value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
ReactiveValue[int] | None
|
Frame signal to evaluate against. Defaults to the active Scene's frame. |
None
|
Source code in src/keyed/builders.py
Keys
¶
Bases: Generic[T]
Build an animation by placing absolute keys on the timeline.
Each key names a frame, a value, and how to arrive there from the previous key:
snapholds the current value, then changes instantly at the named frame.tweeninterpolates from the previous key to this one, with the full gap acting as the duration.
There is no over argument anywhere. Transition duration is determined
implicitly by the gap between consecutive keys.
Use hold to anchor the current value at a
frame so the next tween starts there instead of at the previous key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial
|
HasValue[T]
|
The value before any keys are placed. |
required |
Examples:
from keyed import Color, easing
from keyed.builders import Keys
black = Color(0, 0, 0)
yellow = Color(0.75, 0.75, 0)
red = Color(0.75, 0, 0)
x_color = (
Keys(black)
.hold(108)
.tween(120, yellow, ease=easing.cubic_in_out)
.hold(156)
.tween(300, red, ease=easing.linear_in_out)
.build()
)
Source code in src/keyed/builders.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
snap
¶
snap(frame, to, animation_type=ABSOLUTE)
Hold at the current value and snap instantly to to at frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
int
|
The frame at which the snap occurs. |
required |
to
|
HasValue[T]
|
The value to snap to. |
required |
animation_type
|
AnimationType
|
How to combine with the base value. |
ABSOLUTE
|
Source code in src/keyed/builders.py
hold
¶
Anchor the current value at frame so the next tween starts there.
Use this to delay the start of a smooth transition. The value stays
constant up to frame, and any subsequent
tween begins from there rather than from
the previous key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
int
|
Frame at which to anchor the current value. |
required |
Source code in src/keyed/builders.py
tween
¶
tween(frame, to, ease=linear_in_out, animation_type=ABSOLUTE)
Smoothly interpolate from the previous keyframe to to at frame.
The full gap between the previous keyframe (or frame 0) and frame is
the transition duration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
int
|
The frame at which the value fully arrives. |
required |
to
|
HasValue[T]
|
The target value. |
required |
ease
|
EasingFunctionT
|
Easing function for the transition. |
linear_in_out
|
animation_type
|
AnimationType
|
How to combine with the base value. |
ABSOLUTE
|
Source code in src/keyed/builders.py
build
¶
Build and return the reactive animation value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
ReactiveValue[int] | None
|
Frame signal to evaluate against. Defaults to the active Scene's frame. |
None
|