Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Feature: BraceLabel, BraceText -- Packed brace with its label + several useful methods

mirefek700d62c7ca24
diff --git a/topics/objects.py b/topics/objects.py
index 7fc5d69be..b4643dec0 100644
--- a/topics/objects.py
+++ b/topics/objects.py
@@ -521,19 +521,57 @@ class Broadcast(LaggedStart):
)
+class BraceLabel(VMobject):
+ CONFIG = {
+ "label_constructor" : TexMobject,
+ "label_scale" : 1,
+ }
+ def __init__(self, obj, text, brace_direction = DOWN, **kwargs):
+ VMobject.__init__(self, **kwargs)
+ self.brace_direction = brace_direction
+ if isinstance(obj, list): obj = VMobject(*obj)
+ self.brace = Brace(obj, brace_direction, **kwargs)
+
+ if isinstance(text, tuple) or isinstance(text, list):
+ self.label = self.label_constructor(*text, **kwargs)
+ else: self.label = self.label_constructor(str(text))
+ if self.label_scale != 1: self.label.scale(self.label_scale)
+
+ self.brace.put_at_tip(self.label)
+ self.submobjects = [self.brace, self.label]
+
+ def creation_anim(self, label_anim = FadeIn, brace_anim = GrowFromCenter):
+ return AnimationGroup(brace_anim(self.brace), label_anim(self.label))
+
+ def shift_brace(self, obj, **kwargs):
+ if isinstance(obj, list): obj = VMobject(*obj)
+ self.brace = Brace(obj, self.brace_direction, **kwargs)
+ self.brace.put_at_tip(self.label)
+ self.submobjects[0] = self.brace
+ return self
+ def change_label(self, *text, **kwargs):
+ self.label = self.label_constructor(*text, **kwargs)
+ if self.label_scale != 1: self.label.scale(self.label_scale)
+ self.brace.put_at_tip(self.label)
+ self.submobjects[1] = self.label
+ return self
+ def change_brace_label(self, obj, *text):
+ self.shift_brace(obj)
+ self.change_label(*text)
+ return self
+ def copy(self):
+ copy_mobject = copy.copy(self)
+ copy_mobject.brace = self.brace.copy()
+ copy_mobject.label = self.label.copy()
+ copy_mobject.submobjects = [copy_mobject.brace, copy_mobject.label]
+ return copy_mobject
-
-
-
-
-
-
-
-
-
-
+class BraceText(BraceLabel):
+ CONFIG = {
+ "label_constructor" : TextMobject
+ }