add an example for Text

This commit is contained in:
Tony031218
2021-01-15 21:11:17 +08:00
parent 1d1706039e
commit f696ba4100
2 changed files with 47 additions and 0 deletions

View File

@ -104,6 +104,45 @@ class WarpSquare(Scene):
self.wait()
class TextExample(Scene):
def construct(self):
# To run this scene properly, you should have "Consolas" font in your computer
# for full usage, you can see https://github.com/3b1b/manim/pull/680
text = Text("Here is a text", font="Consolas", size=2)
difference = Text(
"""
The most important difference between Text and TextMobject is that\n
you can change the font more easily, but can't use the LaTeX gramma
""",
font="Arial", size=0.5,
# t2c is a dict that you can choose color for different text
t2c={"Text": BLUE, "TextMobject": BLUE, "LaTeX": ORANGE}
)
VGroup(text, difference).arrange(DOWN, buff=1)
self.play(Write(text))
self.play(FadeIn(difference, UP))
self.wait(3)
fonts = Text(
"And you can also set the font according to different words",
t2f={"font": "Consolas", "words": "Consolas"},
t2c={"font": BLUE, "words": GREEN}
)
slant = Text(
"And the same as slant and weight",
font="Consolas",
t2s={"slant": ITALIC},
t2w={"weight": BOLD},
t2c={"slant": ORANGE, "weight": RED}
)
VGroup(fonts, slant).arrange(DOWN, buff=0.8)
self.play(FadeOut(text), FadeOut(difference, shift=DOWN))
self.play(Write(fonts))
self.wait()
self.play(Write(slant))
self.wait()
class SquareToCircle(Scene):
def construct(self):
circle = Circle()