ProteinMotion
Reference navigation
On this page

CLASS · v0.9.1

Text

Draw shaped vector text over the protein image.

python
from proteinmotion import Text

Constructor

python
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

ParameterDefaultDescription
textRequiredText to display.
font_sizekeyword only36Font 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 only1.3Line spacing multiplier.
ligatureskeyword onlyTrueEnable font ligatures during text shaping.
opacitykeyword only1.0Opacity 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.

Code Scene excerpt
python
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)
Output Preview · 5.0 s · 60 fps
Write and Unwrite

Letter outlines are drawn, filled, and erased.

Methods and properties

NameDescription
set_text()methodReplace text and rebuild its shaped glyphs before adding it to the scene.
glyph_countpropertyNumber of shaped glyphs used for writing animation.
to_corner()methodPlace text near an image corner.
layout()methodProject text and line geometry for the renderer at the current frame.
set_opacity()method · inherited from AnnotationSet or animate opacity in [0, 1].
move_to()method · inherited from AnnotationSet or animate text position in normalized image coordinates.
shift()method · inherited from AnnotationTranslate the object by an offset.
snapshot()method · inherited from AnnotationCapture the current state for deterministic timeline evaluation.
restore()method · inherited from AnnotationRestore a state produced by snapshot().
animateproperty · inherited from AnnotationCreate a builder for fluent animation calls. Pass the result to scene.play().
text_progressproperty · inherited from AnnotationCurrent reveal progress for glyphs and annotation lines.
python
Text.set_text(text)

Replace text and rebuild its shaped glyphs before adding it to the scene.

ParameterDefaultDescription
textRequiredText to display.

Returns: The Text object.

python
Text.glyph_count

Number of shaped glyphs used for writing animation.

python
Text.to_corner(corner='UL', *, buff=0.06)

Place text near an image corner.

ParameterDefaultDescription
corner'UL'"UL", "UR", "DL", or "DR" for an image corner.
buffkeyword only0.06Padding from the image edge in normalized image units.

Returns: The Text object.

python
Text.layout(camera, width, height)

Project text and line geometry for the renderer at the current frame.

ParameterDefaultDescription
cameraRequiredCamera used to project or frame objects.
widthRequiredImage width in pixels.
heightRequiredImage height in pixels.

Returns: AnnotationLayout containing glyph placements and line paths.

Inherited from annotations.Annotation.

python
Text.set_opacity(opacity)

Set or animate opacity in [0, 1].

ParameterDefaultDescription
opacityRequiredOpacity in [0, 1], from transparent to opaque.

Returns: The object or animation builder.

Inherited from annotations.Annotation.

python
Text.move_to(position)

Set or animate text position in normalized image coordinates.

ParameterDefaultDescription
positionRequiredImage 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.

python
Text.shift(offset)

Translate the object by an offset.

ParameterDefaultDescription
offsetRequiredOffset (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.

python
Text.snapshot()

Capture the current state for deterministic timeline evaluation.

Returns: State dictionary.

Inherited from annotations.Annotation.

python
Text.restore(state)

Restore a state produced by snapshot().

ParameterDefaultDescription
stateRequiredState returned by snapshot().

Returns: None

Inherited from annotations.Annotation.

python
Text.animate

Create a builder for fluent animation calls. Pass the result to scene.play().

Inherited from annotations.Annotation.

python
Text.text_progress

Current reveal progress for glyphs and annotation lines.