Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

OpenGL compatibility via metaclass: Matrix, DecimalNumber, Variable (#1585)

Mohammad Al-Fetyani5229aafdafa2
diff --git a/manim/mobject/matrix.py b/manim/mobject/matrix.py
index b4562794e..aa4a590a3 100644
--- a/manim/mobject/matrix.py
+++ b/manim/mobject/matrix.py
@@ -47,6 +47,7 @@ from ..mobject.shape_matchers import BackgroundRectangle
from ..mobject.svg.tex_mobject import MathTex, Tex
from ..mobject.types.vectorized_mobject import VGroup, VMobject
from ..utils.color import WHITE
+from .opengl_compatibility import ConvertToOpenGL
# TO DO : The following two functions are not used in this file.
# Not sure if we should keep it or not.
@@ -67,7 +68,7 @@ def matrix_to_mobject(matrix):
return MathTex(matrix_to_tex_string(matrix))
-class Matrix(VMobject):
+class Matrix(VMobject, metaclass=ConvertToOpenGL):
"""A mobject that displays a matrix on the screen.
Examples
@@ -182,7 +183,7 @@ class Matrix(VMobject):
self.element_alignment_corner = element_alignment_corner
self.left_bracket = left_bracket
self.right_bracket = right_bracket
- VMobject.__init__(self, **kwargs)
+ super().__init__(**kwargs)
mob_matrix = self.matrix_to_mob_matrix(matrix)
self.organize_mob_matrix(mob_matrix)
self.elements = VGroup(*it.chain(*mob_matrix))
diff --git a/manim/mobject/numbers.py b/manim/mobject/numbers.py
index b8f78e0bd..31f87abd9 100644
--- a/manim/mobject/numbers.py
+++ b/manim/mobject/numbers.py
@@ -11,9 +11,10 @@ from ..mobject.svg.tex_mobject import MathTex, SingleStringMathTex
from ..mobject.types.vectorized_mobject import VMobject
from ..mobject.value_tracker import ValueTracker
from ..utils.family import extract_mobject_family_members
+from .opengl_compatibility import ConvertToOpenGL
-class DecimalNumber(VMobject):
+class DecimalNumber(VMobject, metaclass=ConvertToOpenGL):
"""An mobject representing a decimal number.
Examples
@@ -189,13 +190,8 @@ class DecimalNumber(VMobject):
new_decimal.scale(self[-1].height / new_decimal[-1].height)
new_decimal.move_to(self, self.edge_to_fix)
new_decimal.match_style(self)
+ self.become(new_decimal)
- old_family = self.get_family()
- self.submobjects = new_decimal.submobjects
- for mob in old_family:
- # Dumb hack...due to how scene handles families
- # of animated mobjects
- mob.points[:] = 0
self.number = number
return self
@@ -232,7 +228,7 @@ class Integer(DecimalNumber):
return int(np.round(super().get_value()))
-class Variable(VMobject):
+class Variable(VMobject, metaclass=ConvertToOpenGL):
"""A class for displaying text that continuously updates to reflect the value of a python variable.
Automatically adds the text for the label and the value when instantiated and added to the screen.
@@ -342,5 +338,5 @@ class Variable(VMobject):
self.label, RIGHT
)
- VMobject.__init__(self, **kwargs)
+ super().__init__(**kwargs)
self.add(self.label, self.value)