Reference navigation
On this page
CLASS · v0.9.1
Text
Draw shaped vector text over the protein image.
from proteinmotion import TextConstructor
Text(
text,
*,
font_size=36,
font='regular',
color='#edf3fc',
position=(0.06, 0.08),
align='left',
line_spacing=1.3,
ligatures=True,
opacity=1.0,
)Parameters
| Parameter | Default | Description |
|---|---|---|
text | Required | Text to display. |
font_sizekeyword only | 36 | Font size in pixels at a 1080-pixel image height. |
fontkeyword only | 'regular' | Bundled "regular" or "semibold", or a path to a TTF/OTF font. |
colorkeyword only | '#edf3fc' | Hex color or RGB values. For tint setters, None restores the representation’s base palette. |
positionkeyword only | (0.06, 0.08) | Image coordinates (x, y), with (0, 0) at the top-left and (1, 1) at the bottom-right. |
alignkeyword only | 'left' | Horizontal alignment: "left", "center", or "right". |
line_spacingkeyword only | 1.3 | Line spacing multiplier. |
ligatureskeyword only | True | Enable font ligatures during text shaping. |
opacitykeyword only | 1.0 | Opacity in [0, 1], from transparent to opaque. |
Notes
Positions use normalized image coordinates. Font sizes use pixels at a 1080-pixel image height and scale with the rendered height. Text supports Unicode, ligatures, and TTF/OTF fonts.
Example and output
This excerpt runs inside a scene’s construct() method. The full example file includes imports, structure loading, and camera setup. Run it from a repository checkout.
title = Text(
"Protein motion",
font_size=130,
font="semibold",
position=(0.1, 0.38),
)
self.play(
Write(title, lag_ratio=0.12, stroke_width=1.8),
run_time=2.5,
)
self.wait(1)
self.play(Unwrite(title), run_time=1.5)Letter outlines are drawn, filled, and erased.
Methods and properties
| Name | Description |
|---|---|
| set_text()method | Replace text and rebuild its shaped glyphs before adding it to the scene. |
| glyph_countproperty | Number of shaped glyphs used for writing animation. |
| to_corner()method | Place text near an image corner. |
| layout()method | Project text and line geometry for the renderer at the current frame. |
| set_opacity()method · inherited from Annotation | Set or animate opacity in [0, 1]. |
| move_to()method · inherited from Annotation | Set or animate text position in normalized image coordinates. |
| shift()method · inherited from Annotation | Translate the object by an offset. |
| snapshot()method · inherited from Annotation | Capture the current state for deterministic timeline evaluation. |
| restore()method · inherited from Annotation | Restore a state produced by snapshot(). |
| animateproperty · inherited from Annotation | Create a builder for fluent animation calls. Pass the result to scene.play(). |
| text_progressproperty · inherited from Annotation | Current reveal progress for glyphs and annotation lines. |
Text.set_text(text)Replace text and rebuild its shaped glyphs before adding it to the scene.
| Parameter | Default | Description |
|---|---|---|
text | Required | Text to display. |
Returns: The Text object.
Text.glyph_countNumber of shaped glyphs used for writing animation.
Text.to_corner(corner='UL', *, buff=0.06)Place text near an image corner.
| Parameter | Default | Description |
|---|---|---|
corner | 'UL' | "UL", "UR", "DL", or "DR" for an image corner. |
buffkeyword only | 0.06 | Padding from the image edge in normalized image units. |
Returns: The Text object.
Text.layout(camera, width, height)Project text and line geometry for the renderer at the current frame.
| Parameter | Default | Description |
|---|---|---|
camera | Required | Camera used to project or frame objects. |
width | Required | Image width in pixels. |
height | Required | Image height in pixels. |
Returns: AnnotationLayout containing glyph placements and line paths.
Inherited from annotations.Annotation.
Text.set_opacity(opacity)Set or animate opacity in [0, 1].
| Parameter | Default | Description |
|---|---|---|
opacity | Required | Opacity in [0, 1], from transparent to opaque. |
Returns: The object or animation builder.
Inherited from annotations.Annotation.
Text.move_to(position)Set or animate text position in normalized image coordinates.
| Parameter | Default | Description |
|---|---|---|
position | Required | Image coordinates (x, y), with (0, 0) at the top-left and (1, 1) at the bottom-right. |
Returns: The annotation or animation builder.
Inherited from annotations.Annotation.
Text.shift(offset)Translate the object by an offset.
| Parameter | Default | Description |
|---|---|---|
offset | Required | Offset (x, y) in design pixels at 1080p for residue labels; normalized image units for text shifts. |
Returns: The object or animation builder.
Inherited from annotations.Annotation.
Text.snapshot()Capture the current state for deterministic timeline evaluation.
Returns: State dictionary.
Inherited from annotations.Annotation.
Text.restore(state)Restore a state produced by snapshot().
| Parameter | Default | Description |
|---|---|---|
state | Required | State returned by snapshot(). |
Returns: None
Inherited from annotations.Annotation.
Text.animateCreate a builder for fluent animation calls. Pass the result to scene.play().
Inherited from annotations.Annotation.
Text.text_progressCurrent reveal progress for glyphs and annotation lines.