manim 0.17.0__py3-none-any.whl → 0.19.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. manim/__init__.py +11 -6
  2. manim/__main__.py +62 -19
  3. manim/_config/__init__.py +10 -9
  4. manim/_config/cli_colors.py +26 -9
  5. manim/_config/default.cfg +1 -3
  6. manim/_config/logger_utils.py +23 -13
  7. manim/_config/utils.py +662 -468
  8. manim/animation/animation.py +164 -18
  9. manim/animation/changing.py +34 -23
  10. manim/animation/composition.py +265 -67
  11. manim/animation/creation.py +208 -26
  12. manim/animation/fading.py +16 -18
  13. manim/animation/growing.py +35 -15
  14. manim/animation/indication.py +150 -76
  15. manim/animation/movement.py +56 -22
  16. manim/animation/numbers.py +64 -6
  17. manim/animation/rotation.py +78 -7
  18. manim/animation/specialized.py +6 -7
  19. manim/animation/speedmodifier.py +13 -10
  20. manim/animation/transform.py +14 -11
  21. manim/animation/transform_matching_parts.py +3 -4
  22. manim/animation/updaters/mobject_update_utils.py +152 -30
  23. manim/animation/updaters/update.py +10 -7
  24. manim/camera/camera.py +182 -118
  25. manim/camera/mapping_camera.py +34 -3
  26. manim/camera/moving_camera.py +95 -74
  27. manim/camera/multi_camera.py +23 -15
  28. manim/camera/three_d_camera.py +70 -52
  29. manim/cli/__init__.py +17 -0
  30. manim/cli/cfg/group.py +76 -44
  31. manim/cli/checkhealth/checks.py +192 -0
  32. manim/cli/checkhealth/commands.py +90 -0
  33. manim/cli/default_group.py +158 -25
  34. manim/cli/init/commands.py +33 -25
  35. manim/cli/plugins/commands.py +16 -3
  36. manim/cli/render/commands.py +72 -60
  37. manim/cli/render/ease_of_access_options.py +4 -3
  38. manim/cli/render/global_options.py +59 -17
  39. manim/cli/render/output_options.py +6 -5
  40. manim/cli/render/render_options.py +98 -33
  41. manim/constants.py +109 -59
  42. manim/data_structures.py +31 -0
  43. manim/mobject/frame.py +8 -5
  44. manim/mobject/geometry/__init__.py +1 -0
  45. manim/mobject/geometry/arc.py +277 -135
  46. manim/mobject/geometry/boolean_ops.py +32 -31
  47. manim/mobject/geometry/labeled.py +376 -0
  48. manim/mobject/geometry/line.py +192 -87
  49. manim/mobject/geometry/polygram.py +224 -58
  50. manim/mobject/geometry/shape_matchers.py +61 -25
  51. manim/mobject/geometry/tips.py +122 -48
  52. manim/mobject/graph.py +1027 -419
  53. manim/mobject/graphing/coordinate_systems.py +533 -278
  54. manim/mobject/graphing/functions.py +53 -32
  55. manim/mobject/graphing/number_line.py +123 -65
  56. manim/mobject/graphing/probability.py +88 -62
  57. manim/mobject/graphing/scale.py +33 -19
  58. manim/mobject/logo.py +118 -28
  59. manim/mobject/matrix.py +87 -83
  60. manim/mobject/mobject.py +912 -442
  61. manim/mobject/opengl/dot_cloud.py +16 -5
  62. manim/mobject/opengl/opengl_compatibility.py +4 -2
  63. manim/mobject/opengl/opengl_geometry.py +254 -153
  64. manim/mobject/opengl/opengl_image_mobject.py +3 -1
  65. manim/mobject/opengl/opengl_mobject.py +779 -482
  66. manim/mobject/opengl/opengl_point_cloud_mobject.py +41 -14
  67. manim/mobject/opengl/opengl_surface.py +14 -92
  68. manim/mobject/opengl/opengl_three_dimensions.py +12 -8
  69. manim/mobject/opengl/opengl_vectorized_mobject.py +98 -100
  70. manim/mobject/svg/brace.py +173 -41
  71. manim/mobject/svg/svg_mobject.py +139 -53
  72. manim/mobject/table.py +61 -68
  73. manim/mobject/text/code_mobject.py +193 -539
  74. manim/mobject/text/numbers.py +81 -34
  75. manim/mobject/text/tex_mobject.py +130 -78
  76. manim/mobject/text/text_mobject.py +288 -164
  77. manim/mobject/three_d/polyhedra.py +111 -13
  78. manim/mobject/three_d/three_d_utils.py +17 -8
  79. manim/mobject/three_d/three_dimensions.py +239 -106
  80. manim/mobject/types/image_mobject.py +50 -30
  81. manim/mobject/types/point_cloud_mobject.py +120 -75
  82. manim/mobject/types/vectorized_mobject.py +841 -408
  83. manim/mobject/value_tracker.py +105 -38
  84. manim/mobject/vector_field.py +50 -31
  85. manim/opengl/__init__.py +3 -3
  86. manim/plugins/__init__.py +14 -1
  87. manim/plugins/plugins_flags.py +10 -14
  88. manim/renderer/cairo_renderer.py +65 -50
  89. manim/renderer/opengl_renderer.py +89 -69
  90. manim/renderer/opengl_renderer_window.py +39 -18
  91. manim/renderer/shader.py +123 -87
  92. manim/renderer/shader_wrapper.py +44 -28
  93. manim/renderer/vectorized_mobject_rendering.py +38 -10
  94. manim/scene/moving_camera_scene.py +32 -3
  95. manim/scene/scene.py +507 -242
  96. manim/scene/scene_file_writer.py +371 -220
  97. manim/scene/section.py +20 -16
  98. manim/scene/three_d_scene.py +14 -22
  99. manim/scene/vector_space_scene.py +223 -129
  100. manim/scene/zoomed_scene.py +46 -41
  101. manim/typing.py +990 -0
  102. manim/utils/bezier.py +1823 -371
  103. manim/utils/caching.py +12 -5
  104. manim/utils/color/AS2700.py +236 -0
  105. manim/utils/color/BS381.py +318 -0
  106. manim/utils/color/DVIPSNAMES.py +96 -0
  107. manim/utils/color/SVGNAMES.py +179 -0
  108. manim/utils/color/X11.py +533 -0
  109. manim/utils/color/XKCD.py +952 -0
  110. manim/utils/color/__init__.py +61 -0
  111. manim/utils/color/core.py +1667 -0
  112. manim/utils/color/manim_colors.py +218 -0
  113. manim/utils/commands.py +48 -20
  114. manim/utils/config_ops.py +39 -19
  115. manim/utils/debug.py +8 -7
  116. manim/utils/deprecation.py +86 -39
  117. manim/utils/docbuild/__init__.py +17 -0
  118. manim/utils/docbuild/autoaliasattr_directive.py +236 -0
  119. manim/utils/docbuild/autocolor_directive.py +99 -0
  120. manim/utils/docbuild/manim_directive.py +94 -41
  121. manim/utils/docbuild/module_parsing.py +245 -0
  122. manim/utils/exceptions.py +6 -0
  123. manim/utils/family.py +5 -3
  124. manim/utils/family_ops.py +17 -4
  125. manim/utils/file_ops.py +27 -17
  126. manim/utils/hashing.py +55 -45
  127. manim/utils/images.py +13 -7
  128. manim/utils/ipython_magic.py +13 -7
  129. manim/utils/iterables.py +163 -120
  130. manim/utils/module_ops.py +66 -24
  131. manim/utils/opengl.py +77 -24
  132. manim/utils/parameter_parsing.py +32 -0
  133. manim/utils/paths.py +30 -33
  134. manim/utils/polylabel.py +235 -0
  135. manim/utils/qhull.py +218 -0
  136. manim/utils/rate_functions.py +98 -32
  137. manim/utils/simple_functions.py +25 -33
  138. manim/utils/sounds.py +7 -1
  139. manim/utils/space_ops.py +188 -115
  140. manim/utils/testing/__init__.py +17 -0
  141. manim/utils/testing/_frames_testers.py +13 -8
  142. manim/utils/testing/_show_diff.py +5 -3
  143. manim/utils/testing/_test_class_makers.py +34 -18
  144. manim/utils/testing/frames_comparison.py +37 -19
  145. manim/utils/tex.py +130 -198
  146. manim/utils/tex_file_writing.py +77 -47
  147. manim/utils/tex_templates.py +2 -1
  148. manim/utils/unit.py +6 -5
  149. {manim-0.17.0.dist-info → manim-0.19.1.dist-info}/METADATA +64 -65
  150. manim-0.19.1.dist-info/RECORD +220 -0
  151. {manim-0.17.0.dist-info → manim-0.19.1.dist-info}/WHEEL +1 -1
  152. manim-0.19.1.dist-info/entry_points.txt +3 -0
  153. {manim-0.17.0.dist-info → manim-0.19.1.dist-info/licenses}/LICENSE.community +1 -1
  154. manim/cli/new/group.py +0 -189
  155. manim/communitycolors.py +0 -9
  156. manim/gui/__init__.py +0 -0
  157. manim/gui/gui.py +0 -82
  158. manim/plugins/import_plugins.py +0 -43
  159. manim/utils/color.py +0 -552
  160. manim-0.17.0.dist-info/RECORD +0 -206
  161. manim-0.17.0.dist-info/entry_points.txt +0 -4
  162. /manim/cli/{new → checkhealth}/__init__.py +0 -0
  163. {manim-0.17.0.dist-info → manim-0.19.1.dist-info/licenses}/LICENSE +0 -0
manim/mobject/logo.py CHANGED
@@ -4,19 +4,104 @@ from __future__ import annotations
4
4
 
5
5
  __all__ = ["ManimBanner"]
6
6
 
7
+ from typing import Any
8
+
9
+ import svgelements as se
10
+
7
11
  from manim.animation.updaters.update import UpdateFromAlphaFunc
8
12
  from manim.mobject.geometry.arc import Circle
9
13
  from manim.mobject.geometry.polygram import Square, Triangle
10
- from manim.mobject.text.tex_mobject import MathTex, Tex
14
+ from manim.mobject.mobject import Mobject
15
+ from manim.typing import Vector3D
11
16
 
17
+ from .. import constants as cst
12
18
  from ..animation.animation import override_animation
13
19
  from ..animation.composition import AnimationGroup, Succession
14
20
  from ..animation.creation import Create, SpiralIn
15
21
  from ..animation.fading import FadeIn
16
- from ..constants import DOWN, LEFT, ORIGIN, RIGHT, TAU, UP
22
+ from ..mobject.svg.svg_mobject import VMobjectFromSVGPath
17
23
  from ..mobject.types.vectorized_mobject import VGroup
18
- from ..utils.rate_functions import ease_in_out_cubic, ease_out_sine, smooth
19
- from ..utils.tex_templates import TexFontTemplates
24
+ from ..utils.rate_functions import ease_in_out_cubic, smooth
25
+
26
+ MANIM_SVG_PATHS: list[se.Path] = [
27
+ se.Path( # double stroke letter M
28
+ "M4.64259-2.092154L2.739726-6.625156C2.660025-6.824408 2.650062-6.824408 "
29
+ "2.381071-6.824408H.52802C.348692-6.824408 .199253-6.824408 .199253-6.645"
30
+ "081C.199253-6.475716 .37858-6.475716 .428394-6.475716C.547945-6.475716 ."
31
+ "816936-6.455791 1.036115-6.37609V-1.05604C1.036115-.846824 1.036115-.408"
32
+ "468 .358655-.348692C.169365-.328767 .169365-.18929 .169365-.179328C.1693"
33
+ "65 0 .328767 0 .508095 0H2.052304C2.231631 0 2.381071 0 2.381071-.179328"
34
+ "C2.381071-.268991 2.30137-.33873 2.221669-.348692C1.454545-.408468 1.454"
35
+ "545-.826899 1.454545-1.05604V-6.017435L1.464508-6.027397L3.895392-.20921"
36
+ "5C3.975093-.029888 4.044832 0 4.104608 0C4.224159 0 4.254047-.079701 4.3"
37
+ "03861-.199253L6.744707-6.027397L6.75467-6.017435V-1.05604C6.75467-.84682"
38
+ "4 6.75467-.408468 6.07721-.348692C5.88792-.328767 5.88792-.18929 5.88792"
39
+ "-.179328C5.88792 0 6.047323 0 6.22665 0H8.886675C9.066002 0 9.215442 0 9"
40
+ ".215442-.179328C9.215442-.268991 9.135741-.33873 9.05604-.348692C8.28891"
41
+ "7-.408468 8.288917-.826899 8.288917-1.05604V-5.768369C8.288917-5.977584 "
42
+ "8.288917-6.41594 8.966376-6.475716C9.066002-6.485679 9.155666-6.535492 9"
43
+ ".155666-6.645081C9.155666-6.824408 9.006227-6.824408 8.826899-6.824408H6"
44
+ ".90411C6.645081-6.824408 6.625156-6.824408 6.535492-6.615193L4.64259-2.0"
45
+ "92154ZM4.343711-1.912827C4.423412-1.743462 4.433375-1.733499 4.552927-1."
46
+ "693649L4.11457-.637609H4.094645L1.823163-6.057285C1.77335-6.1868 1.69364"
47
+ "9-6.356164 1.554172-6.475716H2.420922L4.343711-1.912827ZM1.334994-.34869"
48
+ "2H1.165629C1.185554-.37858 1.205479-.408468 1.225405-.428394C1.235367-.4"
49
+ "38356 1.235367-.448319 1.24533-.458281L1.334994-.348692ZM7.103362-6.4757"
50
+ "16H8.159402C7.940224-6.22665 7.940224-5.967621 7.940224-5.788294V-1.0361"
51
+ "15C7.940224-.856787 7.940224-.597758 8.169365-.348692H6.884184C7.103362-"
52
+ ".597758 7.103362-.856787 7.103362-1.036115V-6.475716Z"
53
+ ),
54
+ se.Path( # letter a
55
+ "M1.464508-4.024907C1.464508-4.234122 1.743462-4.393524 2.092154-4.393524"
56
+ "C2.669988-4.393524 2.929016-4.124533 2.929016-3.516812V-2.789539C1.77335"
57
+ "-2.440847 .249066-2.042341 .249066-.916563C.249066-.308842 .71731 .13947"
58
+ "7 1.354919 .139477C1.92279 .139477 2.381071-.059776 2.929016-.557908C3.0"
59
+ "38605-.049813 3.257783 .139477 3.745953 .139477C4.174346 .139477 4.48318"
60
+ "8-.019925 4.861768-.428394L4.712329-.637609L4.612702-.537983C4.582814-.5"
61
+ "08095 4.552927-.498132 4.503113-.498132C4.363636-.498132 4.293898-.58779"
62
+ "6 4.293898-.747198V-3.347447C4.293898-4.184309 3.536737-4.712329 2.32129"
63
+ "5-4.712329C1.195517-4.712329 .438356-4.204234 .438356-3.457036C.438356-3"
64
+ ".048568 .67746-2.799502 1.085928-2.799502C1.484433-2.799502 1.763387-3.0"
65
+ "38605 1.763387-3.377335C1.763387-3.676214 1.464508-3.88543 1.464508-4.02"
66
+ "4907ZM2.919054-.996264C2.650062-.687422 2.450809-.56787 2.211706-.56787C"
67
+ "1.912827-.56787 1.703611-.836862 1.703611-1.235367C1.703611-1.8132 2.122"
68
+ "042-2.231631 2.919054-2.440847V-.996264Z"
69
+ ),
70
+ se.Path( # letter n
71
+ "M2.948941-4.044832C3.297634-4.044832 3.466999-3.775841 3.466999-3.217933"
72
+ "V-.806974C3.466999-.438356 3.337484-.278954 2.998755-.239103V0H5.339975V"
73
+ "-.239103C4.951432-.268991 4.851806-.388543 4.851806-.806974V-3.307597C4."
74
+ "851806-4.164384 4.323786-4.712329 3.506849-4.712329C2.909091-4.712329 2."
75
+ "450809-4.433375 2.082192-3.845579V-4.592777H.179328V-4.353674C.617684-4."
76
+ "283935 .707347-4.184309 .707347-3.765878V-.836862C.707347-.418431 .62764"
77
+ "6-.328767 .179328-.239103V0H2.580324V-.239103C2.211706-.288917 2.092154-"
78
+ ".438356 2.092154-.806974V-3.466999C2.092154-3.576588 2.530511-4.044832 2"
79
+ ".948941-4.044832Z"
80
+ ),
81
+ se.Path( # letter i
82
+ "M2.15193-4.592777H.239103V-4.353674C.67746-4.26401 .767123-4.174346 .767"
83
+ "123-3.765878V-.836862C.767123-.428394 .697385-.348692 .239103-.239103V0H"
84
+ "2.6401V-.239103C2.291407-.288917 2.15193-.428394 2.15193-.806974V-4.5927"
85
+ "77ZM1.454545-6.884184C1.026152-6.884184 .67746-6.535492 .67746-6.117061C"
86
+ ".67746-5.668742 1.006227-5.339975 1.444583-5.339975S2.221669-5.668742 2."
87
+ "221669-6.107098C2.221669-6.535492 1.882939-6.884184 1.454545-6.884184Z"
88
+ ),
89
+ se.Path( # letter m
90
+ "M2.929016-4.044832C3.317559-4.044832 3.466999-3.815691 3.466999-3.217933"
91
+ "V-.806974C3.466999-.398506 3.35741-.268991 2.988792-.239103V0H5.32005V-."
92
+ "239103C4.971357-.278954 4.851806-.428394 4.851806-.806974V-3.466999C4.85"
93
+ "1806-3.576588 5.310087-4.044832 5.69863-4.044832C6.07721-4.044832 6.2266"
94
+ "5-3.805729 6.22665-3.217933V-.806974C6.22665-.388543 6.117061-.268991 5."
95
+ "738481-.239103V0H8.109589V-.239103C7.721046-.259029 7.611457-.37858 7.61"
96
+ "1457-.806974V-3.307597C7.611457-4.164384 7.083437-4.712329 6.266501-4.71"
97
+ "2329C5.69863-4.712329 5.32005-4.483188 4.801993-3.845579C4.503113-4.4732"
98
+ "25 4.154421-4.712329 3.526775-4.712329S2.440847-4.443337 2.062267-3.8455"
99
+ "79V-4.592777H.179328V-4.353674C.617684-4.293898 .707347-4.174346 .707347"
100
+ "-3.765878V-.836862C.707347-.428394 .617684-.318804 .179328-.239103V0H2.5"
101
+ "50436V-.239103C2.201743-.288917 2.092154-.428394 2.092154-.806974V-3.466"
102
+ "999C2.092154-3.58655 2.530511-4.044832 2.929016-4.044832Z"
103
+ ),
104
+ ]
20
105
 
21
106
 
22
107
  class ManimBanner(VGroup):
@@ -65,36 +150,41 @@ class ManimBanner(VGroup):
65
150
  m_height_over_anim_height = 0.75748
66
151
 
67
152
  self.font_color = "#ece6e2" if dark_theme else "#343434"
68
- self.scale_factor = 1
153
+ self.scale_factor = 1.0
69
154
 
70
- self.M = MathTex(r"\mathbb{M}").scale(7).set_color(self.font_color)
71
- self.M.shift(2.25 * LEFT + 1.5 * UP)
155
+ self.M = VMobjectFromSVGPath(MANIM_SVG_PATHS[0]).flip(cst.RIGHT).center()
156
+ self.M.set(stroke_width=0).scale(
157
+ 7 * cst.DEFAULT_FONT_SIZE * cst.SCALE_FACTOR_PER_FONT_POINT
158
+ )
159
+ self.M.set_fill(color=self.font_color, opacity=1).shift(
160
+ 2.25 * cst.LEFT + 1.5 * cst.UP
161
+ )
72
162
 
73
- self.circle = Circle(color=logo_green, fill_opacity=1).shift(LEFT)
74
- self.square = Square(color=logo_blue, fill_opacity=1).shift(UP)
75
- self.triangle = Triangle(color=logo_red, fill_opacity=1).shift(RIGHT)
163
+ self.circle = Circle(color=logo_green, fill_opacity=1).shift(cst.LEFT)
164
+ self.square = Square(color=logo_blue, fill_opacity=1).shift(cst.UP)
165
+ self.triangle = Triangle(color=logo_red, fill_opacity=1).shift(cst.RIGHT)
76
166
  self.shapes = VGroup(self.triangle, self.square, self.circle)
77
167
  self.add(self.shapes, self.M)
78
- self.move_to(ORIGIN)
168
+ self.move_to(cst.ORIGIN)
79
169
 
80
170
  anim = VGroup()
81
- for i, ch in enumerate("anim"):
82
- tex = Tex(
83
- "\\textbf{" + ch + "}",
84
- tex_template=TexFontTemplates.gnu_freeserif_freesans,
171
+ for ind, path in enumerate(MANIM_SVG_PATHS[1:]):
172
+ tex = VMobjectFromSVGPath(path).flip(cst.RIGHT).center()
173
+ tex.set(stroke_width=0).scale(
174
+ cst.DEFAULT_FONT_SIZE * cst.SCALE_FACTOR_PER_FONT_POINT
85
175
  )
86
- if i != 0:
176
+ if ind > 0:
87
177
  tex.next_to(anim, buff=0.01)
88
- tex.align_to(self.M, DOWN)
178
+ tex.align_to(self.M, cst.DOWN)
89
179
  anim.add(tex)
90
- anim.set_color(self.font_color)
180
+ anim.set_fill(color=self.font_color, opacity=1)
91
181
  anim.height = m_height_over_anim_height * self.M.height
92
182
 
93
183
  # Note: "anim" is only shown in the expanded state
94
184
  # and thus not yet added to the submobjects of self.
95
185
  self.anim = anim
96
186
 
97
- def scale(self, scale_factor: float, **kwargs) -> ManimBanner:
187
+ def scale(self, scale_factor: float, **kwargs: Any) -> ManimBanner:
98
188
  """Scale the banner by the specified scale factor.
99
189
 
100
190
  Parameters
@@ -133,7 +223,7 @@ class ManimBanner(VGroup):
133
223
  lag_ratio=0.1,
134
224
  )
135
225
 
136
- def expand(self, run_time: float = 1.5, direction="center") -> Succession:
226
+ def expand(self, run_time: float = 1.5, direction: str = "center") -> Succession:
137
227
  """An animation that expands Manim's logo into its banner.
138
228
 
139
229
  The returned animation transforms the banner from its initial
@@ -181,7 +271,7 @@ class ManimBanner(VGroup):
181
271
  m_shape_offset = 6.25 * self.scale_factor
182
272
  shape_sliding_overshoot = self.scale_factor * 0.8
183
273
  m_anim_buff = 0.06
184
- self.anim.next_to(self.M, buff=m_anim_buff).align_to(self.M, DOWN)
274
+ self.anim.next_to(self.M, buff=m_anim_buff).align_to(self.M, cst.DOWN)
185
275
  self.anim.set_opacity(0)
186
276
  self.shapes.save_state()
187
277
  m_clone = self.anim[-1].copy()
@@ -191,9 +281,9 @@ class ManimBanner(VGroup):
191
281
  self.M.save_state()
192
282
  left_group = VGroup(self.M, self.anim, m_clone)
193
283
 
194
- def shift(vector):
284
+ def shift(vector: Vector3D) -> None:
195
285
  self.shapes.restore()
196
- left_group.align_to(self.M.saved_state, LEFT)
286
+ left_group.align_to(self.M.saved_state, cst.LEFT)
197
287
  if direction == "right":
198
288
  self.shapes.shift(vector)
199
289
  elif direction == "center":
@@ -202,14 +292,14 @@ class ManimBanner(VGroup):
202
292
  elif direction == "left":
203
293
  left_group.shift(-vector)
204
294
 
205
- def slide_and_uncover(mob, alpha):
206
- shift(alpha * (m_shape_offset + shape_sliding_overshoot) * RIGHT)
295
+ def slide_and_uncover(mob: Mobject, alpha: float) -> None:
296
+ shift(alpha * (m_shape_offset + shape_sliding_overshoot) * cst.RIGHT)
207
297
 
208
298
  # Add letters when they are covered
209
299
  for letter in mob.anim:
210
300
  if mob.square.get_center()[0] > letter.get_center()[0]:
211
301
  letter.set_opacity(1)
212
- self.add(letter)
302
+ self.add_to_back(letter)
213
303
 
214
304
  # Finish animation
215
305
  if alpha == 1:
@@ -219,13 +309,13 @@ class ManimBanner(VGroup):
219
309
  mob.shapes.save_state()
220
310
  mob.M.save_state()
221
311
 
222
- def slide_back(mob, alpha):
312
+ def slide_back(mob: Mobject, alpha: float) -> None:
223
313
  if alpha == 0:
224
314
  m_clone.set_opacity(1)
225
315
  m_clone.move_to(mob.anim[-1])
226
316
  mob.anim.set_opacity(1)
227
317
 
228
- shift(alpha * shape_sliding_overshoot * LEFT)
318
+ shift(alpha * shape_sliding_overshoot * cst.LEFT)
229
319
 
230
320
  if alpha == 1:
231
321
  mob.remove(m_clone)
manim/mobject/matrix.py CHANGED
@@ -15,8 +15,8 @@ Examples
15
15
  m2 = DecimalMatrix(
16
16
  [[3.456, 2.122], [33.2244, 12.33]],
17
17
  element_to_mobject_config={"num_decimal_places": 2},
18
- left_bracket="\\{",
19
- right_bracket="\\}")
18
+ left_bracket=r"\{",
19
+ right_bracket=r"\}")
20
20
  m3 = MobjectMatrix(
21
21
  [[Circle().scale(0.3), Square().scale(0.3)],
22
22
  [MathTex("\\pi").scale(2), Star().scale(0.3)]],
@@ -40,9 +40,11 @@ __all__ = [
40
40
 
41
41
 
42
42
  import itertools as it
43
- from typing import Iterable, Sequence
43
+ from collections.abc import Callable, Iterable, Sequence
44
+ from typing import Any
44
45
 
45
46
  import numpy as np
47
+ from typing_extensions import Self
46
48
 
47
49
  from manim.mobject.mobject import Mobject
48
50
  from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
@@ -56,7 +58,7 @@ from ..mobject.types.vectorized_mobject import VGroup, VMobject
56
58
  # Not sure if we should keep it or not.
57
59
 
58
60
 
59
- def matrix_to_tex_string(matrix):
61
+ def matrix_to_tex_string(matrix: np.ndarray) -> str:
60
62
  matrix = np.array(matrix).astype("str")
61
63
  if matrix.ndim == 1:
62
64
  matrix = matrix.reshape((matrix.size, 1))
@@ -67,12 +69,45 @@ def matrix_to_tex_string(matrix):
67
69
  return prefix + " \\\\ ".join(rows) + suffix
68
70
 
69
71
 
70
- def matrix_to_mobject(matrix):
72
+ def matrix_to_mobject(matrix: np.ndarray) -> MathTex:
71
73
  return MathTex(matrix_to_tex_string(matrix))
72
74
 
73
75
 
74
76
  class Matrix(VMobject, metaclass=ConvertToOpenGL):
75
- """A mobject that displays a matrix on the screen.
77
+ r"""A mobject that displays a matrix on the screen.
78
+
79
+ Parameters
80
+ ----------
81
+ matrix
82
+ A numpy 2d array or list of lists.
83
+ v_buff
84
+ Vertical distance between elements, by default 0.8.
85
+ h_buff
86
+ Horizontal distance between elements, by default 1.3.
87
+ bracket_h_buff
88
+ Distance of the brackets from the matrix, by default ``MED_SMALL_BUFF``.
89
+ bracket_v_buff
90
+ Height of the brackets, by default ``MED_SMALL_BUFF``.
91
+ add_background_rectangles_to_entries
92
+ ``True`` if should add backgraound rectangles to entries, by default ``False``.
93
+ include_background_rectangle
94
+ ``True`` if should include background rectangle, by default ``False``.
95
+ element_to_mobject
96
+ The mobject class used to construct the elements, by default :class:`~.MathTex`.
97
+ element_to_mobject_config
98
+ Additional arguments to be passed to the constructor in ``element_to_mobject``,
99
+ by default ``{}``.
100
+ element_alignment_corner
101
+ The corner to which elements are aligned, by default ``DR``.
102
+ left_bracket
103
+ The left bracket type, by default ``"["``.
104
+ right_bracket
105
+ The right bracket type, by default ``"]"``.
106
+ stretch_brackets
107
+ ``True`` if should stretch the brackets to fit the height of matrix contents, by default ``True``.
108
+ bracket_config
109
+ Additional arguments to be passed to :class:`~.MathTex` when constructing
110
+ the brackets.
76
111
 
77
112
  Examples
78
113
  --------
@@ -85,22 +120,22 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
85
120
 
86
121
  class MatrixExamples(Scene):
87
122
  def construct(self):
88
- m0 = Matrix([[2, "\\pi"], [-1, 1]])
123
+ m0 = Matrix([[2, r"\pi"], [-1, 1]])
89
124
  m1 = Matrix([[2, 0, 4], [-1, 1, 5]],
90
125
  v_buff=1.3,
91
126
  h_buff=0.8,
92
127
  bracket_h_buff=SMALL_BUFF,
93
128
  bracket_v_buff=SMALL_BUFF,
94
- left_bracket="\\{",
95
- right_bracket="\\}")
129
+ left_bracket=r"\{",
130
+ right_bracket=r"\}")
96
131
  m1.add(SurroundingRectangle(m1.get_columns()[1]))
97
132
  m2 = Matrix([[2, 1], [-1, 3]],
98
133
  element_alignment_corner=UL,
99
134
  left_bracket="(",
100
135
  right_bracket=")")
101
136
  m3 = Matrix([[2, 1], [-1, 3]],
102
- left_bracket="\\\\langle",
103
- right_bracket="\\\\rangle")
137
+ left_bracket=r"\langle",
138
+ right_bracket=r"\rangle")
104
139
  m4 = Matrix([[2, 1], [-1, 3]],
105
140
  ).set_column_colors(RED, GREEN)
106
141
  m5 = Matrix([[2, 1], [-1, 3]],
@@ -137,52 +172,15 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
137
172
  bracket_v_buff: float = MED_SMALL_BUFF,
138
173
  add_background_rectangles_to_entries: bool = False,
139
174
  include_background_rectangle: bool = False,
140
- element_to_mobject: type[MathTex] = MathTex,
175
+ element_to_mobject: type[Mobject] | Callable[..., Mobject] = MathTex,
141
176
  element_to_mobject_config: dict = {},
142
177
  element_alignment_corner: Sequence[float] = DR,
143
178
  left_bracket: str = "[",
144
179
  right_bracket: str = "]",
145
180
  stretch_brackets: bool = True,
146
181
  bracket_config: dict = {},
147
- **kwargs,
182
+ **kwargs: Any,
148
183
  ):
149
- """
150
-
151
- Parameters
152
- ----------
153
- matrix
154
- A numpy 2d array or list of lists.
155
- v_buff
156
- Vertical distance between elements, by default 0.8.
157
- h_buff
158
- Horizontal distance between elements, by default 1.3.
159
- bracket_h_buff
160
- Distance of the brackets from the matrix, by default ``MED_SMALL_BUFF``.
161
- bracket_v_buff
162
- Height of the brackets, by default ``MED_SMALL_BUFF``.
163
- add_background_rectangles_to_entries
164
- ``True`` if should add backgraound rectangles to entries, by default ``False``.
165
- include_background_rectangle
166
- ``True`` if should include background rectangle, by default ``False``.
167
- element_to_mobject
168
- The mobject class used to construct the elements, by default :class:`~.MathTex`.
169
- element_to_mobject_config
170
- Additional arguments to be passed to the constructor in ``element_to_mobject``,
171
- by default ``{}``.
172
- element_alignment_corner
173
- The corner to which elements are aligned, by default ``DR``.
174
- left_bracket
175
- The left bracket type, by default ``"["``.
176
- right_bracket
177
- The right bracket type, by default ``"]"``.
178
- stretch_brackets
179
- ``True`` if should stretch the brackets to fit the height of matrix contents, by default ``True``.
180
- bracket_config
181
- Additional arguments to be passed to :class:`~.MathTex` when constructing
182
- the brackets.
183
-
184
- """
185
-
186
184
  self.v_buff = v_buff
187
185
  self.h_buff = h_buff
188
186
  self.bracket_h_buff = bracket_h_buff
@@ -209,7 +207,7 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
209
207
  if self.include_background_rectangle:
210
208
  self.add_background_rectangle()
211
209
 
212
- def _matrix_to_mob_matrix(self, matrix):
210
+ def _matrix_to_mob_matrix(self, matrix: np.ndarray) -> list[list[Mobject]]:
213
211
  return [
214
212
  [
215
213
  self.element_to_mobject(item, **self.element_to_mobject_config)
@@ -218,7 +216,7 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
218
216
  for row in matrix
219
217
  ]
220
218
 
221
- def _organize_mob_matrix(self, matrix):
219
+ def _organize_mob_matrix(self, matrix: list[list[Mobject]]) -> Self:
222
220
  for i, row in enumerate(matrix):
223
221
  for j, _ in enumerate(row):
224
222
  mob = matrix[i][j]
@@ -228,7 +226,7 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
228
226
  )
229
227
  return self
230
228
 
231
- def _add_brackets(self, left: str = "[", right: str = "]", **kwargs):
229
+ def _add_brackets(self, left: str = "[", right: str = "]", **kwargs: Any) -> Self:
232
230
  """Adds the brackets to the Matrix mobject.
233
231
 
234
232
  See Latex document for various bracket types.
@@ -245,7 +243,6 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
245
243
  :class:`Matrix`
246
244
  The current matrix object (self).
247
245
  """
248
-
249
246
  # Height per row of LaTeX array with default settings
250
247
  BRACKET_HEIGHT = 0.5977
251
248
 
@@ -283,13 +280,13 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
283
280
  self.add(l_bracket, r_bracket)
284
281
  return self
285
282
 
286
- def get_columns(self):
287
- """Return columns of the matrix as VGroups.
283
+ def get_columns(self) -> VGroup:
284
+ r"""Return columns of the matrix as VGroups.
288
285
 
289
286
  Returns
290
287
  --------
291
- List[:class:`~.VGroup`]
292
- Each VGroup contains a column of the matrix.
288
+ :class:`~.VGroup`
289
+ The VGroup contains a nested VGroup for each column of the matrix.
293
290
 
294
291
  Examples
295
292
  --------
@@ -299,11 +296,10 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
299
296
 
300
297
  class GetColumnsExample(Scene):
301
298
  def construct(self):
302
- m0 = Matrix([["\\pi", 3], [1, 5]])
299
+ m0 = Matrix([[r"\pi", 3], [1, 5]])
303
300
  m0.add(SurroundingRectangle(m0.get_columns()[1]))
304
301
  self.add(m0)
305
302
  """
306
-
307
303
  return VGroup(
308
304
  *(
309
305
  VGroup(*(row[i] for row in self.mob_matrix))
@@ -311,8 +307,8 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
311
307
  )
312
308
  )
313
309
 
314
- def set_column_colors(self, *colors: str):
315
- """Set individual colors for each columns of the matrix.
310
+ def set_column_colors(self, *colors: str) -> Self:
311
+ r"""Set individual colors for each columns of the matrix.
316
312
 
317
313
  Parameters
318
314
  ----------
@@ -341,13 +337,13 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
341
337
  column.set_color(color)
342
338
  return self
343
339
 
344
- def get_rows(self):
345
- """Return rows of the matrix as VGroups.
340
+ def get_rows(self) -> VGroup:
341
+ r"""Return rows of the matrix as VGroups.
346
342
 
347
343
  Returns
348
344
  --------
349
- List[:class:`~.VGroup`]
350
- Each VGroup contains a row of the matrix.
345
+ :class:`~.VGroup`
346
+ The VGroup contains a nested VGroup for each row of the matrix.
351
347
 
352
348
  Examples
353
349
  --------
@@ -363,8 +359,8 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
363
359
  """
364
360
  return VGroup(*(VGroup(*row) for row in self.mob_matrix))
365
361
 
366
- def set_row_colors(self, *colors: str):
367
- """Set individual colors for each row of the matrix.
362
+ def set_row_colors(self, *colors: str) -> Self:
363
+ r"""Set individual colors for each row of the matrix.
368
364
 
369
365
  Parameters
370
366
  ----------
@@ -393,7 +389,7 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
393
389
  row.set_color(color)
394
390
  return self
395
391
 
396
- def add_background_to_entries(self):
392
+ def add_background_to_entries(self) -> Self:
397
393
  """Add a black background rectangle to the matrix,
398
394
  see above for an example.
399
395
 
@@ -406,7 +402,7 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
406
402
  mob.add_background_rectangle()
407
403
  return self
408
404
 
409
- def get_mob_matrix(self):
405
+ def get_mob_matrix(self) -> list[list[Mobject]]:
410
406
  """Return the underlying mob matrix mobjects.
411
407
 
412
408
  Returns
@@ -416,7 +412,7 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
416
412
  """
417
413
  return self.mob_matrix
418
414
 
419
- def get_entries(self):
415
+ def get_entries(self) -> VGroup:
420
416
  """Return the individual entries of the matrix.
421
417
 
422
418
  Returns
@@ -441,13 +437,13 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
441
437
  """
442
438
  return self.elements
443
439
 
444
- def get_brackets(self):
445
- """Return the bracket mobjects.
440
+ def get_brackets(self) -> VGroup:
441
+ r"""Return the bracket mobjects.
446
442
 
447
443
  Returns
448
444
  --------
449
- List[:class:`~.VGroup`]
450
- Each VGroup contains a bracket
445
+ :class:`~.VGroup`
446
+ A VGroup containing the left and right bracket.
451
447
 
452
448
  Examples
453
449
  --------
@@ -468,7 +464,7 @@ class Matrix(VMobject, metaclass=ConvertToOpenGL):
468
464
 
469
465
 
470
466
  class DecimalMatrix(Matrix):
471
- """A mobject that displays a matrix with decimal entries on the screen.
467
+ r"""A mobject that displays a matrix with decimal entries on the screen.
472
468
 
473
469
  Examples
474
470
  --------
@@ -489,9 +485,9 @@ class DecimalMatrix(Matrix):
489
485
  def __init__(
490
486
  self,
491
487
  matrix: Iterable,
492
- element_to_mobject: Mobject = DecimalNumber,
493
- element_to_mobject_config: dict[str, Mobject] = {"num_decimal_places": 1},
494
- **kwargs,
488
+ element_to_mobject: type[Mobject] = DecimalNumber,
489
+ element_to_mobject_config: dict[str, Any] = {"num_decimal_places": 1},
490
+ **kwargs: Any,
495
491
  ):
496
492
  """
497
493
  Will round/truncate the decimal places as per the provided config.
@@ -532,7 +528,10 @@ class IntegerMatrix(Matrix):
532
528
  """
533
529
 
534
530
  def __init__(
535
- self, matrix: Iterable, element_to_mobject: Mobject = Integer, **kwargs
531
+ self,
532
+ matrix: Iterable,
533
+ element_to_mobject: type[Mobject] = Integer,
534
+ **kwargs: Any,
536
535
  ):
537
536
  """
538
537
  Will round if there are decimal entries in the matrix.
@@ -548,7 +547,7 @@ class IntegerMatrix(Matrix):
548
547
 
549
548
 
550
549
  class MobjectMatrix(Matrix):
551
- """A mobject that displays a matrix of mobject entries on the screen.
550
+ r"""A mobject that displays a matrix of mobject entries on the screen.
552
551
 
553
552
  Examples
554
553
  --------
@@ -566,7 +565,12 @@ class MobjectMatrix(Matrix):
566
565
  self.add(m0)
567
566
  """
568
567
 
569
- def __init__(self, matrix, element_to_mobject=lambda m: m, **kwargs):
568
+ def __init__(
569
+ self,
570
+ matrix: Iterable,
571
+ element_to_mobject: type[Mobject] | Callable[..., Mobject] = lambda m: m,
572
+ **kwargs: Any,
573
+ ):
570
574
  super().__init__(matrix, element_to_mobject=element_to_mobject, **kwargs)
571
575
 
572
576
 
@@ -575,7 +579,7 @@ def get_det_text(
575
579
  determinant: int | str | None = None,
576
580
  background_rect: bool = False,
577
581
  initial_scale_factor: float = 2,
578
- ):
582
+ ) -> VGroup:
579
583
  r"""Helper function to create determinant.
580
584
 
581
585
  Parameters