-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_create_animations.py
82 lines (70 loc) · 2.51 KB
/
text_create_animations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import pygments.styles as code_styles
from manim import *
def create_code(code_str):
code_style = code_styles.get_style_by_name("material")
return Code(
code=code_str,
language="python",
line_spacing=1.15,
insert_line_no=False,
background="window",
font="Hack Nerd Font Mono",
style=code_style,
)
class AnimationsScene(Scene):
def construct(self):
title = MarkupText(
f"Text <b><i>Animations</i></b> in <span foreground='{BLUE}'><b><u>Manim</u></b></span>",
)
self.play(Write(title))
self.play(title.animate.to_edge(UP), run_time=3)
example_str = """
This is a multiline line string with multiple words
to show text animations in manim
"""
code_strs = [
"self.play(AddTextLetterByLetter(string), run_time=5)",
"self.play(SpiralIn(string), run_time=5)",
"self.play(DrawBorderThenFill(string), run_time=5)",
"self.play(ShowIncreasingSubsets(string), run_time=5)",
"self.play(ShowSubmobjectsOneByOne(string), run_time=5)",
"self.play(AddTextWordByWord(string), run_time=5)",
"self.play(Unwrite(string), run_time=5)",
]
code_objs = [create_code(code_str) for code_str in code_strs]
animations = [
AddTextLetterByLetter,
SpiralIn,
DrawBorderThenFill,
ShowIncreasingSubsets,
ShowSubmobjectsOneByOne,
AddTextWordByWord,
Unwrite,
]
words = [
"AddTextLetterByLetter",
"SpiralIn",
"DrawBorderThenFill",
"ShowIncreasingSubsets",
"ShowSubmobjectsOneByOne",
"AddTextWordByWord",
"Unwrite",
]
word_locations = [
(string.find(word), string.find(word) + len(word))
for string, word in zip(code_strs, words)
]
example = Text(example_str)
RUN_TIME = 8
for code, animation, locs in zip(code_objs, animations, word_locations):
self.play(Write(code))
self.play(code.animate.next_to(title, DOWN))
text_to_indicate = code.code[0][locs[0] : locs[1]]
self.play(
animation(example),
Circumscribe(code.code[0]),
Indicate(text_to_indicate),
run_time=RUN_TIME,
)
self.wait(2)
self.play(FadeOut(code), FadeOut(example))