Transformations¶
keyed.transforms
¶
Transform objects by rotations, translations, scale, and more.
Transformable
¶
A base class for things that have a geometry.
Source code in src/keyed/transforms.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 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 148 149 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 260 261 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 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
|
rotate
¶
rotate(amount, start=ALWAYS, end=ALWAYS, easing=cubic_in_out, center=None, direction=ORIGIN)
Rotate the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
amount
|
HasValue[float]
|
Amount to rotate by. |
required |
start
|
int
|
The frame to start rotating. |
ALWAYS
|
end
|
int
|
The frame to end rotating. |
ALWAYS
|
easing
|
EasingFunctionT
|
The easing function to use. |
cubic_in_out
|
center
|
ReactiveValue[GeometryT] | None
|
The object around which to rotate. |
None
|
direction
|
Direction
|
The relative critical point of the center. |
ORIGIN
|
Returns:
Type | Description |
---|---|
Self
|
self |
Source code in src/keyed/transforms.py
scale
¶
scale(amount, start=ALWAYS, end=ALWAYS, easing=cubic_in_out, center=None, direction=ORIGIN)
Scale the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
amount
|
HasValue[float]
|
Amount to scale by. |
required |
start
|
int
|
The frame to start scaling. |
ALWAYS
|
end
|
int
|
The frame to end scaling. |
ALWAYS
|
easing
|
EasingFunctionT
|
The easing function to use. |
cubic_in_out
|
center
|
ReactiveValue[GeometryT] | None
|
The object around which to rotate. |
None
|
direction
|
Direction
|
The relative critical point of the center. |
ORIGIN
|
Returns:
Type | Description |
---|---|
Self
|
self |
Source code in src/keyed/transforms.py
translate
¶
translate(x=0, y=0, start=ALWAYS, end=ALWAYS, easing=cubic_in_out)
Translate the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
HasValue[float]
|
x offset. |
0
|
y
|
HasValue[float]
|
y offset. |
0
|
start
|
int
|
The frame to start translating. |
ALWAYS
|
end
|
int
|
The frame to end translating. |
ALWAYS
|
easing
|
EasingFunctionT
|
The easing function to use. |
cubic_in_out
|
Source code in src/keyed/transforms.py
move_to
¶
move_to(x=None, y=None, start=ALWAYS, end=ALWAYS, easing=cubic_in_out, center=None, direction=ORIGIN)
Move object to absolute coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
HasValue[float] | None
|
Destination x coordinate |
None
|
y
|
HasValue[float] | None
|
Destination y coordinate |
None
|
start
|
int
|
Starting frame, by default ALWAYS |
ALWAYS
|
end
|
int
|
Ending frame, by default ALWAYS |
ALWAYS
|
easing
|
EasingFunctionT
|
Easing function, by default cubic_in_out |
cubic_in_out
|
Returns:
Type | Description |
---|---|
Self
|
Self |
Source code in src/keyed/transforms.py
align_to
¶
align_to(to, start=ALWAYS, lock=None, end=ALWAYS, from_=None, easing=cubic_in_out, direction=ORIGIN, center_on_zero=False)
Align the object to another object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to
|
Transformable
|
The object to align to. |
required |
start
|
int
|
Start of animation (begin aligning to the object). |
ALWAYS
|
end
|
int
|
End of animation (finish aligning to the object at this frame, and then stay there). |
ALWAYS
|
from_
|
ReactiveValue[GeometryT] | None
|
Use this object as self when doing the alignment. This is helpful for code animations. It is sometimes desirable to align, say, the top-left edge of one character in a TextSelection to the top-left of another character. |
None
|
easing
|
EasingFunctionT
|
The easing function to use. |
cubic_in_out
|
direction
|
Direction
|
The critical point of to and from_to use for the alignment. |
ORIGIN
|
center_on_zero
|
bool
|
If true, align along the "0"-valued dimensions. Otherwise, only align to on non-zero directions. This is beneficial for, say, centering the object at the origin (which has a vector that consists of two zeros). |
False
|
Returns:
Type | Description |
---|---|
Self
|
self |
Source code in src/keyed/transforms.py
lock_on
¶
Lock on to a target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target
|
Transformable
|
Object to lock onto |
required |
reference
|
ReactiveValue[GeometryT] | None
|
Measure from this object. This is useful for TextSelections, where you want to align to a particular character in the selection. |
None
|
start
|
int
|
When to start locking on. |
ALWAYS
|
end
|
int
|
When to end locking on. |
-ALWAYS
|
x
|
bool
|
If true, lock on in the x dimension. |
True
|
y
|
bool
|
If true, lock on in the y dimension. |
True
|
Source code in src/keyed/transforms.py
lock_on2
¶
lock_on2(target, reference=None, direction=ORIGIN, x=True, y=True)
Lock on to a target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target
|
Transformable
|
Object to lock onto |
required |
reference
|
ReactiveValue[GeometryT] | None
|
Measure from this object. This is useful for TextSelections, where you want to align to a particular character in the selection. |
None
|
x
|
bool
|
If true, lock on in the x dimension. |
True
|
y
|
bool
|
if true, lock on in the y dimension. |
True
|
Source code in src/keyed/transforms.py
shear
¶
shear(angle_x=0, angle_y=0, start=ALWAYS, end=ALWAYS, easing=cubic_in_out, center=None)
Shear the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle_x
|
HasValue[float]
|
Angle (in degrees) to shear by along x direction. |
0
|
angle_y
|
HasValue[float]
|
Angle (in degrees) to shear by along x direction. |
0
|
start
|
int
|
The frame to start scaling. |
ALWAYS
|
end
|
int
|
The frame to end scaling. |
ALWAYS
|
easing
|
EasingFunctionT
|
The easing function to use. |
cubic_in_out
|
center
|
ReactiveValue[GeometryT] | None
|
The object around which to rotate. |
None
|
Returns:
Type | Description |
---|---|
Self
|
self |
Source code in src/keyed/transforms.py
stretch
¶
stretch(scale_x=1, scale_y=1, start=ALWAYS, end=ALWAYS, easing=cubic_in_out, center=None, direction=ORIGIN)
Stretch the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale_x
|
HasValue[float]
|
Amount to scale by in x direction. |
1
|
scale_y
|
HasValue[float]
|
Amount to scale by in y direction. |
1
|
start
|
int
|
The frame to start scaling. |
ALWAYS
|
end
|
int
|
The frame to end scaling. |
ALWAYS
|
easing
|
EasingFunctionT
|
The easing function to use. |
cubic_in_out
|
center
|
ReactiveValue[GeometryT] | None
|
The object around which to rotate. |
None
|
direction
|
Direction
|
The relative critical point of the center. |
ORIGIN
|
Returns:
Type | Description |
---|---|
Self
|
self |
Source code in src/keyed/transforms.py
next_to
¶
next_to(to, start=ALWAYS, end=ALWAYS, easing=cubic_in_out, offset=10.0, direction=LEFT)
Align the object to another object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to
|
Transformable
|
The object to align to. |
required |
start
|
int
|
Start of animation (begin aligning to the object). |
ALWAYS
|
end
|
int
|
End of animation (finish aligning to the object at this frame, and then stay there). |
ALWAYS
|
easing
|
EasingFunctionT
|
The easing function to use. |
cubic_in_out
|
offset
|
HasValue[float]
|
Distance between objects (in pixels). |
10.0
|
direction
|
Direction
|
The critical point of to and from_to use for the alignment. |
LEFT
|
Returns:
Type | Description |
---|---|
Self
|
self |
Source code in src/keyed/transforms.py
TransformControls
¶
Control how transforms are applied to the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Transformable
|
A reference to the object being transformed. |
required |
Todo
Passing obj seems a little awkward.
Source code in src/keyed/transforms.py
base_matrix
¶
Get the base transform matrix.
This applies only the translations, rotations, and scale from potentially animated attributes on the object's controls. applying on the rotation, translations matrix at the specified frame.
Returns:
Type | Description |
---|---|
Computed[Matrix]
|
The transform matrix, before any transformations. |
Source code in src/keyed/transforms.py
lock_on
¶
Lock one object's position onto another object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target
|
ReactiveValue[GeometryT]
|
The object to lock onto. |
required |
reference
|
ReactiveValue[GeometryT]
|
The object to use as reference for self when locking on. This is useful, when the overall object, self, is large, and you want to more precisely lock onto a point. |
required |
frame
|
ReactiveValue[int]
|
The reactive value for the scene's frame counter. |
required |
start
|
int
|
The first frame to begin translating. |
ALWAYS
|
end
|
int
|
The final frame to end translating. |
-ALWAYS
|
direction
|
Direction
|
The position in the 2D unit square in the geometry that you want to retrieve. |
ORIGIN
|
x
|
bool
|
If true, lock on in the x dimension. |
True
|
y
|
bool
|
If true, lock on in the y dimension. |
True
|
Source code in src/keyed/transforms.py
affine_transform
¶
Apply the cairo.Matrix as shapely affine transform to the provided geometry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geom
|
GeometryT
|
Geometry to transform |
required |
matrix
|
Matrix | None
|
Transformation matrix |
required |
Returns:
Type | Description |
---|---|
GeometryT
|
The transformed geometry. |
Source code in src/keyed/transforms.py
translate
¶
translate(start, end, delta_x, delta_y, frame, ease=cubic_in_out)
Translate matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int
|
Start frame |
required |
end
|
int
|
End frame |
required |
delta_x
|
HasValue[float]
|
Amount to translate in the x direction. |
required |
delta_y
|
HasValue[float]
|
Amount to translate in the y direction. |
required |
frame
|
ReactiveValue[int]
|
Frame reactive value. |
required |
ease
|
EasingFunctionT
|
Easing function. |
cubic_in_out
|
Returns:
Type | Description |
---|---|
Computed[Matrix]
|
The time-varying transformation matrix. |
Source code in src/keyed/transforms.py
move_to
¶
move_to(start, end, x, y, cx, cy, frame, easing=cubic_in_out)
Create a transformation matrix that moves an object to absolute coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int
|
Starting frame of the movement. |
required |
end
|
int
|
Ending frame of the movement. |
required |
x
|
HasValue[float] | None
|
Target x coordinate. If None, ignore. |
required |
y
|
HasValue[float] | None
|
Target y coordinate. If None, ignore. |
required |
frame
|
ReactiveValue[int]
|
Current frame. |
required |
easing
|
EasingFunctionT
|
Easing function for the movement. |
cubic_in_out
|
Returns:
Name | Type | Description |
---|---|---|
matrix |
Computed[Matrix]
|
Transform matrix for the movement |
Source code in src/keyed/transforms.py
rotate
¶
rotate(start, end, amount, cx, cy, frame, ease=cubic_in_out)
Rotate matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int
|
Start frame |
required |
end
|
int
|
End frame |
required |
amount
|
HasValue[float]
|
Amount to rotate by |
required |
cx
|
HasValue[float]
|
Center x |
required |
cy
|
HasValue[float]
|
Center y |
required |
frame
|
ReactiveValue[int]
|
Frame reactive value. |
required |
ease
|
EasingFunctionT
|
Easing function. |
cubic_in_out
|
Returns:
Type | Description |
---|---|
Computed[Matrix]
|
The time-varying transformation matrix. |
Source code in src/keyed/transforms.py
scale
¶
scale(start, end, amount, cx, cy, frame, ease=cubic_in_out)
Scale matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int
|
Start frame |
required |
end
|
int
|
End frame |
required |
amount
|
HasValue[float]
|
Amount to scale by |
required |
cx
|
HasValue[float]
|
Center x |
required |
cy
|
HasValue[float]
|
Center y |
required |
frame
|
ReactiveValue[int]
|
Frame reactive value. |
required |
ease
|
EasingFunctionT
|
Easing function. |
cubic_in_out
|
Returns:
Type | Description |
---|---|
Computed[Matrix]
|
The time-varying transformation matrix. |
Source code in src/keyed/transforms.py
stretch
¶
stretch(start, end, scale_x, scale_y, cx, cy, frame, ease=cubic_in_out)
Create a non-uniform scaling transformation matrix.
This transformation allows independent scaling in x and y directions, centered around a specified point. Unlike the basic scale transform, this allows for effects like squash and stretch animation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int
|
Starting frame for the animation |
required |
end
|
int
|
Ending frame for the animation |
required |
scale_x
|
HasValue[float]
|
Scale factor for x-axis |
required |
scale_y
|
HasValue[float]
|
Scale factor for y-axis |
required |
cx
|
HasValue[float]
|
X coordinate of the center point |
required |
cy
|
HasValue[float]
|
Y coordinate of the center point |
required |
frame
|
ReactiveValue[int]
|
Current frame |
required |
ease
|
EasingFunctionT
|
Easing function to apply |
cubic_in_out
|
Returns:
Type | Description |
---|---|
Computed[Matrix]
|
A computed transformation matrix |
Source code in src/keyed/transforms.py
shear
¶
shear(start, end, angle_x, angle_y, cx, cy, frame, ease=cubic_in_out)
Create a shear transformation matrix.
A shear transformation slants the shape by a specified amount in either the x or y direction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int
|
Starting frame for the animation |
required |
end
|
int
|
Ending frame for the animation |
required |
angle_x
|
HasValue[float]
|
Angle in degrees to shear along x-axis |
required |
angle_y
|
HasValue[float]
|
Angle in degrees to shear along y-axis |
required |
cx
|
HasValue[float]
|
X coordinate of the center point |
required |
cy
|
HasValue[float]
|
Y coordinate of the center point |
required |
frame
|
ReactiveValue[int]
|
Current frame |
required |
ease
|
EasingFunctionT
|
Easing function to apply |
cubic_in_out
|
Returns:
Type | Description |
---|---|
Computed[Matrix]
|
A computed transformation matrix |
Source code in src/keyed/transforms.py
match_size
¶
match_size(start, end, target_width, target_height, original_width, original_height, cx, cy, frame, match_x=True, match_y=True, ease=cubic_in_out)
Create a transformation matrix that resizes an object to match target dimensions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int
|
Starting frame for the animation |
required |
end
|
int
|
Ending frame for the animation |
required |
target_width
|
HasValue[float]
|
Target width to match |
required |
target_height
|
HasValue[float]
|
Target height to match |
required |
original_width
|
HasValue[float]
|
Current width of the object |
required |
original_height
|
HasValue[float]
|
Current height of the object |
required |
cx
|
HasValue[float]
|
X coordinate of the center point |
required |
cy
|
HasValue[float]
|
Y coordinate of the center point |
required |
frame
|
ReactiveValue[int]
|
Current frame |
required |
match_x
|
bool
|
Whether to match the width |
True
|
match_y
|
bool
|
Whether to match the height |
True
|
ease
|
EasingFunctionT
|
Easing function to apply |
cubic_in_out
|
Returns:
Type | Description |
---|---|
Computed[Matrix]
|
A computed transformation matrix |
Source code in src/keyed/transforms.py
next_to
¶
next_to(start, end, target_x, target_y, self_x, self_y, direction, offset, frame, ease=cubic_in_out)
Create a transformation matrix that positions an object next to a target point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int
|
Starting frame for the animation |
required |
end
|
int
|
Ending frame for the animation |
required |
target_x
|
HasValue[float]
|
X coordinate of the reference point on the target |
required |
target_y
|
HasValue[float]
|
Y coordinate of the reference point on the target |
required |
self_x
|
HasValue[float]
|
X coordinate of the reference point on self |
required |
self_y
|
HasValue[float]
|
Y coordinate of the reference point on self |
required |
direction
|
Direction
|
Direction vector indicating the positioning direction |
required |
offset
|
HasValue[float]
|
Distance between the objects along the direction vector |
required |
frame
|
ReactiveValue[int]
|
Current frame |
required |
ease
|
EasingFunctionT
|
Easing function to apply |
cubic_in_out
|
Returns:
Type | Description |
---|---|
Computed[Matrix]
|
A computed transformation matrix |
Source code in src/keyed/transforms.py
get_position_along_dim_now
¶
get_position_along_dim_now(geom, direction=ORIGIN, dim=0)
Get value of a position along a dimension at the current frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geom
|
GeometryT
|
A Geometry |
required |
direction
|
Direction
|
The position in the 2D unit square in the geometry that you want to retrieve. |
ORIGIN
|
dim
|
Literal[0, 1]
|
Dimension to query, where 0 is the horizontal direction and 1 is the vertical direction. |
0
|
Returns:
Type | Description |
---|---|
float
|
Position along dimension. |
Source code in src/keyed/transforms.py
get_critical_point_now
¶
get_critical_point_now(geom, direction=ORIGIN)
Get value of a position along both dimensions at the current frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
direction
|
Direction
|
The position in the 2D unit square in the geometry that you want to retrieve. |
ORIGIN
|
Returns:
Type | Description |
---|---|
tuple[float, float]
|
The critical point as a tuple of the x and y directions. |
Source code in src/keyed/transforms.py
get_critical_point
¶
get_critical_point(geom, direction=ORIGIN)
Get value of a position along both dimensions at the current frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
direction
|
Direction
|
The position in the 2D unit square in the geometry that you want to retrieve. |
ORIGIN
|
Returns:
Type | Description |
---|---|
tuple[Computed[float], Computed[float]]
|
The critical point as a tuple of reactive values in the x and y directions. |