A community-maintained Python framework for creating mathematical animations.
flash through pi creature class working
Ben Hambrecht8207687a61bf
diff --git a/active_projects/eop/chapter1/quiz_result.py b/active_projects/eop/chapter1/quiz_result.pyindex 823c7e193..4d7a0f38e 100644--- a/active_projects/eop/chapter1/quiz_result.py+++ b/active_projects/eop/chapter1/quiz_result.py@@ -2,11 +2,12 @@ from big_ol_pile_of_manim_imports import *from active_projects.eop.reusable_imports import *from active_projects.eop.independence import *-from for_3b1b_videos.pi_class import *+from for_3b1b_videos.pi_class import PiCreatureClassclass QuizResult(PiCreatureScene):CONFIG = {- "pi_creatures_start_on_screen" : False+ "pi_creatures_start_on_screen" : False,+ "random_seed" : 6}def construct(self):@@ -182,8 +183,8 @@ class QuizResult(PiCreatureScene):prob_label.move_to(percentage_label)self.play(all_students[8].set_color, MAROON_E,- all_students[:8].fade, 0.6,- all_students[9:].fade, 0.6,+ #all_students[:8].fade, 0.6,+ #all_students[9:].fade, 0.6,ReplacementTransform(percentage_label, prob_label))@@ -192,18 +193,32 @@ class QuizResult(PiCreatureScene):FadeOut(arrows))- for i in range(1):- self.play(- FlashThroughHistogram(+ flash_hist = FlashThroughHistogram(grade_hist,direction = "vertical",mode = "random",cell_opacity = 0.5,- run_time = 1- ),- FlashThroughClass(+ run_time = 5,+ rate_func = linear+ )++ flash_class = FlashThroughClass(all_students,mode = "random",- run_time = 5+ highlight_color = MAROON_E,+ run_time = 5,+ rate_func = linear)- )++ for i in range(3):+ self.play(flash_hist, flash_class)+ self.remove(flash_hist.prototype_cell)+++++++++diff --git a/active_projects/eop/reusables/histograms.py b/active_projects/eop/reusables/histograms.pyindex 933d94a29..91c12e86e 100644--- a/active_projects/eop/reusables/histograms.py+++ b/active_projects/eop/reusables/histograms.py@@ -201,7 +201,10 @@ class FlashThroughHistogram(Animation):"hist_opacity" : 0.2}- def __init__(self, mobject, direction = "horizontal", mode = "random", **kwargs):+ def __init__(self, mobject,+ direction = "horizontal",+ mode = "random",+ **kwargs):digest_config(self, kwargs)@@ -277,14 +280,14 @@ class FlashThroughHistogram(Animation):self.mobject.remove(self.prototype_cell)- def clean_up(self):+ def clean_up(self, surrounding_scene = None):+ Animation.clean_up(self, surrounding_scene)self.update(1)- self.remove(prototype_cell)if surrounding_scene is not None:if self.is_remover():- surrounding_scene.remove(self.mobject)+ surrounding_scene.remove(self.prototype_cell)else:- surrounding_scene.add(self.mobject)+ surrounding_scene.add(self.prototype_cell)return selfdiff --git a/for_3b1b_videos/pi_class.py b/for_3b1b_videos/pi_class.pyindex 576ac89f0..2c0479d78 100644--- a/for_3b1b_videos/pi_class.py+++ b/for_3b1b_videos/pi_class.py@@ -1,4 +1,10 @@-from for_3b1b_videos.pi_creature import *+import numpy as np+import warnings++from constants import *++from mobject.types.vectorized_mobject import VGroup+from for_3b1b_videos.pi_creature import PiCreatureclass PiCreatureClass(VGroup):CONFIG = {@@ -15,25 +21,3 @@ class PiCreatureClass(VGroup):self.add(pi)--def FlashThroughClass(Animation):- CONFIG = {- "highlight_color" : GREEN,- }-- def __init__(self, mobject, mode = "linear", **kwargs):-- digest_config(self, kwargs)- self.indices = range(self.height * self.width)-- if mode == "random":- np.random.shuffle(self.indices)-- Animation.__init__(self, mobject, **kwargs)--- def update_mobject(self, alpha):- index = int(np.floor(alpha * self.height * self.width))- for pi in self.mobject:- pi.set_color(BLUE_E)- self.mobject[index].set_color(self.highlight_color)diff --git a/for_3b1b_videos/pi_creature_animations.py b/for_3b1b_videos/pi_creature_animations.pyindex 352ae5ce8..96721b7ff 100644--- a/for_3b1b_videos/pi_creature_animations.py+++ b/for_3b1b_videos/pi_creature_animations.py@@ -6,6 +6,7 @@ from mobject.mobject import Groupfrom mobject.svg.drawings import SpeechBubble+from animation.animation import Animationfrom animation.creation import ShowCreationfrom animation.creation import Writefrom animation.composition import AnimationGroup@@ -16,6 +17,8 @@ from utils.config_ops import digest_configfrom utils.rate_functions import squish_rate_funcfrom utils.rate_functions import there_and_back+from for_3b1b_videos.pi_class import PiCreatureClass+class Blink(ApplyMethod):CONFIG = {@@ -101,3 +104,46 @@ class RemovePiCreatureBubble(AnimationGroup):self.pi_creature.bubble = Noneif surrounding_scene is not None:surrounding_scene.add(self.pi_creature)++++class FlashThroughClass(Animation):+ CONFIG = {+ "highlight_color" : GREEN,+ }++ def __init__(self, mobject, mode = "linear", **kwargs):++ if not isinstance(mobject, PiCreatureClass):+ raise Exception("FlashThroughClass mobject must be a PiCreatureClass")+ digest_config(self, kwargs)+ self.indices = range(mobject.height * mobject.width)++ if mode == "random":+ np.random.shuffle(self.indices)++ Animation.__init__(self, mobject, **kwargs)+++ def update_mobject(self, alpha):+ index = int(np.floor(alpha * self.mobject.height * self.mobject.width))++ for pi in self.mobject:+ pi.set_color(BLUE_E)+ if index < self.mobject.height * self.mobject.width:+ self.mobject[self.indices[index]].set_color(self.highlight_color)+++++++++++++++