A community-maintained Python framework for creating mathematical animations.
Finished eoc8
Grant Sandersonc3b8b36e4e10
diff --git a/eoc/chapter8.py b/eoc/chapter8.pyindex f323d77d9..c41615051 100644--- a/eoc/chapter8.py+++ b/eoc/chapter8.py@@ -568,7 +568,8 @@ class ConstantVelocityCar(Scene):class ConstantVelocityPlot(PlotVelocity):CONFIG = {- "x_axis_label" : "Time"+ "x_axis_label" : "Time",+ "units_of_area_color" : BLUE_E,}def construct(self):self.setup_axes()@@ -684,7 +685,7 @@ class ConstantVelocityPlot(PlotVelocity):square = Square(stroke_color = BLACK,stroke_width = 1,- fill_color = PINK,+ fill_color = self.units_of_area_color,fill_opacity = 1,)square.replace(@@ -712,6 +713,7 @@ class ConstantVelocityPlot(PlotVelocity):)self.play(Indicate(self.y_axis_label_mob))self.play(FadeOut(y_line))+for FadeClass in FadeIn, FadeOut:self.play(FadeClass(@@ -756,6 +758,8 @@ class PiecewiseConstantPlot(PlotVelocity):"tick_size" : 0.2,}def construct(self):+ self.force_skipping()+self.setup_graph()self.always_changing()self.show_piecewise_constant_graph()@@ -1089,7 +1093,9 @@ class PiecewiseConstantPlot(PlotVelocity):def show_v_dt_for_all_rectangles(self):dt_brace_group = VGroup(self.dt_brace, self.dt_label)- rects_subset = self.rects[10:15]+ rects_subset = self.rects[10:20]++ self.revert_to_original_skipping_status()last_rect = Nonefor rect in rects_subset:@@ -1385,9 +1391,18 @@ class PiecewiseConstantPlot(PlotVelocity):ticks.highlight(YELLOW)return ticks+class DontKnowHowToHandleNonConstant(TeacherStudentsScene):+ def construct(self):+ self.play(*[+ ApplyMethod(pi.change, "maybe", UP)+ for pi in self.get_pi_creatures()+ ])+ self.dither(3)+class CarJourneyApproximation(Scene):CONFIG = {"n_jumps" : 5,+ "bottom_words" : "Approximated motion (5 jumps)",}def construct(self):points = [5*LEFT + v for v in UP, 2*DOWN]@@ -1395,8 +1410,9 @@ class CarJourneyApproximation(Scene):h_line = Line(LEFT, RIGHT).scale(SPACE_WIDTH)words = [TextMobject("Real motion (smooth)").shift(3*UP),- TextMobject("Approximated motion (jerky)").shift(0.5*DOWN),+ TextMobject(self.bottom_words).shift(0.5*DOWN),]+ words[1].highlight(GREEN)self.add(h_line, *cars + words)@@ -1427,6 +1443,7 @@ class CarJourneyApproximation(Scene):class LessWrongCarJourneyApproximation(CarJourneyApproximation):CONFIG = {"n_jumps" : 20,+ "bottom_words" : "Better approximation (20 jumps)",}class TellMeThatsNotSurprising(TeacherStudentsScene):@@ -2715,9 +2732,64 @@ class NextVideo(TeacherStudentsScene):self.play(Write(integral))self.dither(5)+class Chapter8PatreonThanks(PatreonThanks):+ CONFIG = {+ "specific_patrons" : [+ "Ali Yahya",+ "CrypticSwarm",+ "Kaustuv DeBiswas",+ "Kathryn Schmiedicke",+ "Karan Bhargava",+ "Ankit Agarwal",+ "Yu Jun",+ "Dave Nicponski",+ "Damion Kistler",+ "Juan Benet",+ "Othman Alikhan",+ "Markus Persson",+ "Dan Buchoff",+ "Derek Dai",+ "Joseph John Cox",+ "Luc Ritchie",+ "Robert Teed",+ "Jason Hise",+ "Meshal Alshammari",+ "Bernd Sing",+ "Nils Schneider",+ "James Thornton",+ "Mustafa Mahdi",+ "Jonathan Eppele",+ "Mathew Bramson",+ "Jerry Ling",+ "Mark Govea",+ "Vecht",+ "Shimin Kuang",+ "Rish Kundalia",+ "Achille Brighton",+ "Ripta Pasay",+ ]+ }+class Thumbnail(FundamentalTheorem):+ CONFIG = {+ "x_axis_label" : "",+ "y_axis_label" : "",+ "graph_origin" : 1.5*DOWN + 4*LEFT,+ "y_axis_height" : 5,+ }+ def construct(self):+ self.setup_axes()+ graph = self.get_graph(+ lambda x : -0.01*x*(x-3)*(x-6)*(x-12) + 3,+ color = YELLOW+ )+ rects = self.get_riemann_rectangles(+ graph,+ x_min = 1, x_max = 8,+ dx = 0.5,+ )-+ self.add(rects, graph)diff --git a/topics/characters.py b/topics/characters.pyindex 470924e92..d42785b3b 100644--- a/topics/characters.py+++ b/topics/characters.py@@ -125,7 +125,7 @@ class PiCreature(SVGMobject):def change(self, new_mode, look_at_arg = None):self.change_mode(new_mode)- if look_at_arg:+ if look_at_arg is not None:self.look_at(look_at_arg)return self@@ -184,7 +184,6 @@ class PiCreature(SVGMobject):self.look(top_mouth_point - bottom_mouth_point)return self-def get_all_pi_creature_modes():result = []prefix = "PiCreatures_"@@ -196,7 +195,6 @@ def get_all_pi_creature_modes():)return result-class Randolph(PiCreature):pass #Nothing more than an alternative name@@ -206,7 +204,6 @@ class Mortimer(PiCreature):"flip_at_start" : True,}-class Mathematician(PiCreature):CONFIG = {"color" : GREY,@@ -232,7 +229,6 @@ class BabyPiCreature(PiCreature):pupil.scale_in_place(self.pupil_scale_factor)self.look(looking_direction)-class Blink(ApplyMethod):CONFIG = {"rate_func" : squish_rate_func(there_and_back)@@ -360,7 +356,7 @@ class RemovePiCreatureBubble(AnimationGroup):if surrounding_scene is not None:surrounding_scene.add(self.pi_creature)-+###########class PiCreatureScene(Scene):CONFIG = {@@ -566,7 +562,6 @@ class PiCreatureScene(Scene):for pi in pi_creatures]))-class TeacherStudentsScene(PiCreatureScene):CONFIG = {"student_colors" : [BLUE_D, BLUE_C, BLUE_E],diff --git a/topics/common_scenes.py b/topics/common_scenes.pyindex 735627987..da78c0ceb 100644--- a/topics/common_scenes.py+++ b/topics/common_scenes.py@@ -3,7 +3,7 @@ from helpers import *from scene.scene import Scenefrom animation.simple_animations import Write, DrawBorderThenFill-from animation.transform import FadeIn, ApplyMethod+from animation.transform import FadeIn, FadeOut, ApplyMethodfrom mobject.vectorized_mobject import VGroupfrom mobject.tex_mobject import TexMobject, TextMobjectfrom topics.characters import Mortimer, Blink@@ -90,8 +90,9 @@ class PatreonThanks(Scene):"Ripta Pasay","Felipe Diniz",],- "max_patrons_height" : 2*SPACE_HEIGHT - 1,+ "patron_group_size" : 8,"patron_scale_val" : 0.7,+}def construct(self):morty = Mortimer()@@ -105,59 +106,41 @@ class PatreonThanks(Scene):patreon_logo = PatreonLogo()patreon_logo.next_to(morty, UP, buff = MED_LARGE_BUFF)- left_patrons = VGroup(*map(TextMobject,- self.specific_patrons[:n_patrons/2]- ))- right_patrons = VGroup(*map(TextMobject,- self.specific_patrons[n_patrons/2:]- ))- for patrons in left_patrons, right_patrons:- patrons.arrange_submobjects(- DOWN, aligned_edge = LEFT,- buff = 1.5*MED_SMALL_BUFF- )-- all_patrons = VGroup(left_patrons, right_patrons)- all_patrons.scale(self.patron_scale_val)- for patrons, vect in (left_patrons, LEFT), (right_patrons, RIGHT):- patrons.to_edge(vect, buff = MED_SMALL_BUFF)- if patrons.get_height() > 2*SPACE_HEIGHT - LARGE_BUFF:- patrons.to_edge(UP, buff = MED_SMALL_BUFF)-- shift_distance = max(- 0, (all_patrons.get_height() - 2*SPACE_HEIGHT)- )- if shift_distance > 0:- shift_distance += 1- velocity = shift_distance/9.0- def get_shift_anim():- return ApplyMethod(- all_patrons.shift, velocity*UP,- rate_func = None- )+ patrons = map(TextMobject, self.specific_patrons)+ patron_groups = []+ index = 0+ counter = 0+ while index < len(patrons):+ next_index = index + self.patron_group_size+ group = VGroup(*patrons[index:next_index])+ group.arrange_submobjects(DOWN, aligned_edge = LEFT)+ if counter%2 == 0:+ group.to_edge(LEFT)+ else:+ group.to_edge(RIGHT)+ patron_groups.append(group)+ index = next_index+ counter += 1self.play(morty.change_mode, "gracious",DrawBorderThenFill(patreon_logo),)self.play(Write(special_thanks, run_time = 1))- self.play(- Write(left_patrons),- morty.look_at, left_patrons- )- self.play(- Write(right_patrons),- morty.look_at, right_patrons- )- self.play(Blink(morty), get_shift_anim())- for patrons in left_patrons, right_patrons:- for index in 0, -1:- self.play(- morty.look_at, patrons[index],- get_shift_anim()- )- self.play(get_shift_anim())-+ for i, group in enumerate(patron_groups):+ anims = [+ FadeIn(+ group, run_time = 2,+ submobject_mode = "lagged_start",+ lag_factor = 4,+ ),+ morty.look_at, group.get_top(),+ ]+ if i >= 2:+ anims.append(FadeOut(patron_groups[i-2]))+ self.play(*anims)+ self.play(morty.look_at, group.get_bottom())+ self.play(Blink(morty))