MCPcopy
hub / github.com/3b1b/manim / construct

Method construct

example_scenes.py:72–112  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

70
71class AnimatingMethods(Scene):
72 def construct(self):
73 grid = Tex(R"\pi").get_grid(10, 10, height=4)
74 self.add(grid)
75
76 # You can animate the application of mobject methods with the
77 # ".animate" syntax:
78 self.play(grid.animate.shift(LEFT))
79
80 # Both of those will interpolate between the mobject's initial
81 # state and whatever happens when you apply that method.
82 # For this example, calling grid.shift(LEFT) would shift the
83 # grid one unit to the left, but both of the previous calls to
84 # "self.play" animate that motion.
85
86 # The same applies for any method, including those setting colors.
87 self.play(grid.animate.set_color(YELLOW))
88 self.wait()
89 self.play(grid.animate.set_submobject_colors_by_gradient(BLUE, GREEN))
90 self.wait()
91 self.play(grid.animate.set_height(TAU - MED_SMALL_BUFF))
92 self.wait()
93
94 # The method Mobject.apply_complex_function lets you apply arbitrary
95 # complex functions, treating the points defining the mobject as
96 # complex numbers.
97 self.play(grid.animate.apply_complex_function(np.exp), run_time=5)
98 self.wait()
99
100 # Even more generally, you could apply Mobject.apply_function,
101 # which takes in functions form R^3 to R^3
102 self.play(
103 grid.animate.apply_function(
104 lambda p: [
105 p[0] + 0.5 * math.sin(p[1]),
106 p[1] + 0.5 * math.sin(p[0]),
107 p[2]
108 ]
109 ),
110 run_time=5,
111 )
112 self.wait()
113
114
115class TextExample(Scene):

Callers

nothing calls this directly

Calls 11

TexClass · 0.85
get_gridMethod · 0.80
playMethod · 0.80
shiftMethod · 0.80
waitMethod · 0.80
set_heightMethod · 0.80
addMethod · 0.45
set_colorMethod · 0.45
apply_functionMethod · 0.45

Tested by

no test coverage detected