Text¶
keyed.text
¶
Drawable objects related to Text.
Text
¶
Bases: Base
A single line of text that can be drawn on screen.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene
|
Scene
|
Scene to draw on |
required |
text
|
HasValue[str]
|
Text content to display |
required |
size
|
float
|
Font size. |
24
|
x
|
HasValue[float] | None
|
X position. Default uses scene center. |
None
|
y
|
HasValue[float] | None
|
Y position. Default uses scene center. |
None
|
font
|
str
|
Font family name. |
'Anonymous Pro'
|
color
|
tuple[float, float, float]
|
RGB color tuple. |
(1, 1, 1)
|
fill_color
|
tuple[float, float, float] | None
|
Optional color to use for inner portion of outlined text. |
None
|
alpha
|
float
|
Opacity from 0-1. |
1.0
|
slant
|
FontSlant
|
Font slant style. |
FONT_SLANT_NORMAL
|
weight
|
FontWeight
|
Font weight. |
FONT_WEIGHT_NORMAL
|
operator
|
Operator
|
Cairo operator for blending. |
OPERATOR_OVER
|
Source code in src/keyed/text.py
29 30 31 32 33 34 35 36 37 38 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 |
|
draw
¶
Draw the text to the scene.
Source code in src/keyed/text.py
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
emphasize
¶
emphasize(buffer=5, radius=0, fill_color=(1, 1, 1), color=(1, 1, 1), alpha=1, dash=None, line_width=2, draw_fill=True, draw_stroke=True, operator=OPERATOR_SCREEN)
Emphasize the object by drawing a rectangle around it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
buffer
|
float
|
The buffer distance around the object's geometry for the emphasis. |
5
|
radius
|
float
|
The corner radius of the emphasized area. |
0
|
fill_color
|
tuple[float, float, float]
|
The fill color of the emphasis as an RGB tuple. |
(1, 1, 1)
|
color
|
tuple[float, float, float]
|
The stroke color of the emphasis as an RGB tuple. |
(1, 1, 1)
|
alpha
|
float
|
The alpha transparency of the emphasis. |
1
|
dash
|
tuple[Sequence[float], float] | None
|
The dash pattern for the emphasis outline. Default is solid line. |
None
|
line_width
|
float
|
The line width of the emphasis outline. |
2
|
draw_fill
|
bool
|
Whether to draw the fill of the emphasis. |
True
|
draw_stroke
|
bool
|
Whether to draw the stroke of the emphasis. |
True
|
operator
|
Operator
|
The compositing operator to use for drawing the emphasis. |
OPERATOR_SCREEN
|
Returns:
Type | Description |
---|---|
Rectangle
|
A Rectangle object representing the emphasized area around the original object. |
Notes
This creates a Rectangle instance and sets up dynamic expressions to follow the geometry of the object as it changes through different frames, applying the specified emphasis effects. Emphasis should generally be applied after all animations on the original object have been added.
Source code in src/keyed/base.py
set
¶
set(property, value, frame=ALWAYS)
Set a property of the object at a specific frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
property
|
str
|
The name of the property to set. |
required |
value
|
Any
|
The new value for the property. |
required |
frame
|
int
|
The frame at which the property value should be set. |
ALWAYS
|
Returns:
Type | Description |
---|---|
Self
|
Self |
See Also
Source code in src/keyed/base.py
set_literal
¶
center
¶
center(frame=ALWAYS)
fade
¶
fade(value, start, end, ease=linear_in_out)
Control the object's alpha parameter to fade it in or out.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
HasValue[float]
|
Value to set alpha to. |
required |
start
|
int
|
Frame to start changing alpha. |
required |
end
|
int
|
Frame to finish changing alpha. |
required |
ease
|
EasingFunctionT
|
Easing function |
linear_in_out
|
Returns:
Type | Description |
---|---|
Self
|
Self |
Source code in src/keyed/base.py
line_to
¶
Create a line connecting this object to another object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Base
|
The target object to connect to |
required |
self_direction
|
Direction
|
Direction for the connection point on this object |
RIGHT
|
other_direction
|
Direction
|
Direction for the connection point on the target object |
LEFT
|
**line_kwargs
|
Any
|
Additional arguments to pass to the Line constructor. |
{}
|
Returns:
Type | Description |
---|---|
'Line'
|
The created Line object |
Source code in src/keyed/base.py
TextSelection
¶
Bases: Selection[CodeTextT]
A sequence of BaseText objects, allowing collective transformations and animations.
Source code in src/keyed/text.py
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 |
|
write_on
¶
Sequentially animates a property across all objects in the selection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
property
|
str
|
The property to animate. |
required |
animator
|
Callable
|
The animation factory function to apply to each object. |
required |
start
|
int
|
The frame at which the first animation should start. |
required |
delay
|
int
|
The delay in frames before starting the next object's animation. |
required |
duration
|
int
|
The duration of each object's animation in frames. |
required |
skip_whitespace
|
bool
|
Whether to skip whitespace characters. |
True
|
See Also
Source code in src/keyed/text.py
is_whitespace
¶
Determine if all objects in the selection are whitespace.
Returns:
Type | Description |
---|---|
bool
|
True if all objects are whitespace, False otherwise. |
contains
¶
filter_whitespace
¶
Filter out all objects that are whitespace from the selection.
Returns:
Type | Description |
---|---|
TextSelection
|
A new TextSelection containing only non-whitespace objects. |
Source code in src/keyed/text.py
highlight
¶
highlight(color=(1, 1, 1), alpha=1, dash=None, operator=OPERATOR_SCREEN, line_width=1, tension=1)
Highlight text by drawing a curve passing through the text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color
|
tuple[float, float, float]
|
The color to use for highlighting as an RGB tuple. |
(1, 1, 1)
|
alpha
|
float
|
The transparency level of the highlight. |
1
|
dash
|
tuple[Sequence[float], float] | None
|
Dash pattern for the highlight stroke. |
None
|
operator
|
Operator
|
The compositing operator to use for rendering the highlight. |
OPERATOR_SCREEN
|
line_width
|
float
|
The width of the highlight stroke. |
1
|
tension
|
float
|
The tension for the curve fitting the text. A value of 0 will draw a linear path betwee points, where as a non-zero value will allow some slack in the bezier curve connecting each set of points. |
1
|
Returns:
Type | Description |
---|---|
Curve
|
A Curve passing through all characters in the underlying text. |
Source code in src/keyed/text.py
Code
¶
Bases: TextSelection[_Line]
A code block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene
|
Scene
|
The scene in which the code is displayed. |
required |
tokens
|
list[StyledToken]
|
A list of styled tokens that make up the code. |
required |
font
|
str
|
The font family used for the code text. |
'Anonymous Pro'
|
font_size
|
int
|
The font size used for the code text. |
24
|
x
|
float
|
The x-coordinate for the position of the code. |
10
|
y
|
float
|
The y-coordinate for the position of the code. |
10
|
alpha
|
float
|
The opacity level of the code text. |
1
|
operator
|
Operator
|
The compositing operator used to render the code. |
OPERATOR_OVER
|
_ascent_correction
|
bool
|
Whether to adjust the y-position based on the font's ascent. |
True
|
See Also
Source code in src/keyed/text.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
|
find_line
¶
find_token
¶
find_char
¶
write_on
¶
Sequentially animates a property across all objects in the selection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
property
|
str
|
The property to animate. |
required |
animator
|
Callable
|
The animation factory function to apply to each object. |
required |
start
|
int
|
The frame at which the first animation should start. |
required |
delay
|
int
|
The delay in frames before starting the next object's animation. |
required |
duration
|
int
|
The duration of each object's animation in frames. |
required |
skip_whitespace
|
bool
|
Whether to skip whitespace characters. |
True
|
See Also
Source code in src/keyed/text.py
is_whitespace
¶
Determine if all objects in the selection are whitespace.
Returns:
Type | Description |
---|---|
bool
|
True if all objects are whitespace, False otherwise. |
contains
¶
filter_whitespace
¶
Filter out all objects that are whitespace from the selection.
Returns:
Type | Description |
---|---|
TextSelection
|
A new TextSelection containing only non-whitespace objects. |
Source code in src/keyed/text.py
highlight
¶
highlight(color=(1, 1, 1), alpha=1, dash=None, operator=OPERATOR_SCREEN, line_width=1, tension=1)
Highlight text by drawing a curve passing through the text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color
|
tuple[float, float, float]
|
The color to use for highlighting as an RGB tuple. |
(1, 1, 1)
|
alpha
|
float
|
The transparency level of the highlight. |
1
|
dash
|
tuple[Sequence[float], float] | None
|
Dash pattern for the highlight stroke. |
None
|
operator
|
Operator
|
The compositing operator to use for rendering the highlight. |
OPERATOR_SCREEN
|
line_width
|
float
|
The width of the highlight stroke. |
1
|
tension
|
float
|
The tension for the curve fitting the text. A value of 0 will draw a linear path betwee points, where as a non-zero value will allow some slack in the bezier curve connecting each set of points. |
1
|
Returns:
Type | Description |
---|---|
Curve
|
A Curve passing through all characters in the underlying text. |
Source code in src/keyed/text.py
keyed.highlight
¶
Syntax highlighting.
StyledToken
¶
Bases: BaseModel
A pydantic model for serializing pygments output.
Source code in src/keyed/highlight.py
KeyedFormatter
¶
Bases: Formatter
Format syntax highlighted text as JSON with color, slant, and weight metadata.
Source code in src/keyed/highlight.py
tokenize
¶
Tokenize code text into styled tokens.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The code text to tokenize. |
required |
lexer
|
Lexer | None
|
The Pygments lexer to use. If None, PythonLexer is used. |
None
|
formatter
|
Formatter | None
|
The Pygments formatter to use. If None, KeyedFormatter is used. |
None
|
filename
|
str
|
The filename of the code, used for more accurate analysis with |
'<unknown>'
|
Returns:
Type | Description |
---|---|
list[StyledToken]
|
List of styled tokens. |