Text
(text, fill_opacity=1, stroke_width=0, color='#FFFFFF', size=1, line_spacing=- 1, font='', slant='NORMAL', weight='NORMAL', t2c=None, t2f=None, t2g=None, t2s=None, t2w=None, gradient=None, tab_width=4, height=None, width=None, should_center=True, unpack_groups=True, disable_ligatures=False, **kwargs)[source]¶Bases: manim.mobject.svg.svg_mobject.SVGMobject
Display (non-LaTeX) text rendered using Pango.
Text objects behave like a VGroup
-like iterable of all characters
in the given text. In particular, slicing is possible.
text (str
) – The text that need to created as mobject.
fill_opacity (int) –
stroke_width (int) –
color (str) –
size (int) –
line_spacing (int) –
font (str) –
slant (str) –
weight (str) –
t2c (Dict[str, str]) –
t2f (Dict[str, str]) –
t2g (Dict[str, tuple]) –
t2s (Dict[str, str]) –
t2w (Dict[str, str]) –
gradient (tuple) –
tab_width (int) –
height (int) –
width (int) –
should_center (bool) –
unpack_groups (bool) –
disable_ligatures (bool) –
The mobject like VGroup
.
Examples
class Example1Text(Scene):
def construct(self):
text = Text('Hello world').scale(3)
self.add(text)
class TextColorExample(Scene):
def construct(self):
text1 = Text('Hello world', color=BLUE).scale(3)
text2 = Text('Hello world', gradient=(BLUE, GREEN)).scale(3).next_to(text1, DOWN)
self.add(text1, text2)
class TextItalicAndBoldExample(Scene):
def construct(self):
text0 = Text('Hello world', slant=ITALIC)
text1 = Text('Hello world', t2s={'world':ITALIC})
text2 = Text('Hello world', weight=BOLD)
text3 = Text('Hello world', t2w={'world':BOLD})
self.add(text0,text1, text2,text3)
for i,mobj in enumerate(self.mobjects):
mobj.shift(DOWN*(i-1))
class TextMoreCustomization(Scene):
def construct(self):
text1 = Text(
'Google',
t2c={'[:1]': '#3174f0', '[1:2]': '#e53125',
'[2:3]': '#fbb003', '[3:4]': '#3174f0',
'[4:5]': '#269a43', '[5:]': '#e53125'}, size=1.2).scale(3)
self.add(text1)
As Text
uses Pango to render text, rendering non-English
characters is easily possible:
class MultipleFonts(Scene):
def construct(self):
morning = Text("வணக்கம்", font="sans-serif")
chin = Text(
"見 角 言 谷 辛 辰 辵 邑 酉 釆 里!", t2c={"見 角 言": BLUE}
) # works same as ``Text``.
mess = Text("Multi-Language", style=BOLD)
russ = Text("Здравствуйте मस नम म ", font="sans-serif")
hin = Text("नमस्ते", font="sans-serif")
arb = Text(
"صباح الخير \n تشرفت بمقابلتك", font="sans-serif"
) # don't mix RTL and LTR languages nothing shows up then ;-)
japanese = Text("臂猿「黛比」帶著孩子", font="sans-serif")
self.add(morning,chin,mess,russ,hin,arb,japanese)
for i,mobj in enumerate(self.mobjects):
mobj.shift(DOWN*(i-3))
class PangoRender(Scene):
def construct(self):
morning = Text("வணக்கம்", font="sans-serif")
self.play(Write(morning))
self.wait(2)
Tests
Check that the creation of Text
works:
>>> Text('The horse does not eat cucumber salad.')
Text('The horse does not eat cucumber salad.')
Methods
Internally used function. |
|
|
|
Internally used function. |
|
Internally used. |
|
Internally used function. |
|
Internally used function. |
|
Internally used function. |
Attributes
|
Used to animate the application of a method. |
find_indexes
(word, text)[source]¶Internally used function. Finds the indexes of text
in word
.
word (str) –
text (str) –
set_color_by_t2g
(t2g=None)[source]¶Internally used. Sets gradient colors for specified
strings. Behaves similarly to set_color_by_t2c
.