Text of a text object
|Mandatory||String or function|
The attribute Text represents the text of a text object. It may be a text string or a function generating a text string at runtime.
t := plot::Text2d("hello world", [0, 0]),
the text is the first argument. Internally, it is stored as the attribute Text = "hello world" and can be accessed and changed via a slot call t::Text.
In most cases, the text is given as a string.
Note: Note that this string has to be quoted when changing it in the "property inspector" of the interactive graphics tool (see section Viewer, Browser, and Inspector: Interactive Manipulation of this document). If the string contains white space and the quotes are removed, the recalculation following the change will produce a syntax error!
A text given by a fixed string cannot be animated. Use a procedure to create animated texts.
The attribute Text can be a procedure that is called at runtime with the animation parameter as the only input parameter. The return value is used as the text of the text object in the corresponding frame of the animation. If the result is not a string, expr2text is applied to the return value.
Usually, a text is given by a string:
t := plot::Text2d("hello world", [1, 1], TextFont = ): plot(t)
We access and change the text:
t::Text := "HELLO WORLD": plot(t)
The same message in 3D:
plot(plot::Text3d("HELLO WORLD", [1, 1, 1], TextFont = ))
The text of a text object can be animated if the text string is provided by a procedure. We use stringlib::formatf to format the animation parameter that is passed to the procedure as a floating-point number for each frame of the animation:
plot(plot::Rectangle(-1..1, -1..1), plot::Text2d(a -> stringlib::formatf(a, 2, 5)." sec", [0, 0], a = 0..20, TextFont = , HorizontalAlignment = Center, VerticalAlignment = Center), Axes = Frame, Frames = 201, TimeRange = 0..20)
Here is the corresponding example in 3D:
plot(plot::Text3d(a -> stringlib::formatf(a, 2, 5)." sec", [0, 0, 0], a = 0..20, TextFont = , HorizontalAlignment = Center, VerticalAlignment = Center), Axes = Frame, Frames = 201, TimeRange = 0..20)