A community-maintained Python framework for creating mathematical animations.
tweaking EoP Chapter 1 (Brick Row Scene finish confirmed?)
Ben Hambrecht84e5fc62f7a2
diff --git a/active_projects/eop/chapter1/brick_row_scene.py b/active_projects/eop/chapter1/brick_row_scene.pyindex a4c0b19e0..521d2b05a 100644--- a/active_projects/eop/chapter1/brick_row_scene.py+++ b/active_projects/eop/chapter1/brick_row_scene.py@@ -152,7 +152,7 @@ class BrickRowScene(PiCreatureScene):def merge_tallies(self, row, target_pos = UP):-+r = row.subdiv_levelif np.all(target_pos == DOWN):@@ -218,7 +218,8 @@ class BrickRowScene(PiCreatureScene):def construct(self):-+ self.force_skipping()+randy = self.get_primary_pi_creature()randy = randy.scale(0.5).move_to(3*DOWN + 6*LEFT)#self.add(randy)@@ -789,6 +790,9 @@ class BrickRowScene(PiCreatureScene):self.wait()self.row = self.merge_rects_by_subdiv(self.row)+++ self.revert_to_original_skipping_status()self.wait()@@ -832,23 +836,16 @@ class BrickRowScene(PiCreatureScene):index = 0old_tally_sizes = [choose(n,i) for i in range(n + 1)]new_tally_sizes = [choose(n + 1,i) for i in range(n + 2)]+for i in range(n + 2):size = new_tally_sizes[i]grouped_target_outcomes.add(VGroup(target_outcomes[index:index + size]))index += size- self.play(- Transform(grouped_outcomes[k][0],grouped_target_outcomes[k][0][old_tally_sizes[k - 1]:])- )-- self.play(- Transform(grouped_outcomes_copy[k][0],grouped_target_outcomes[k + 1][0][:old_tally_sizes[k]])- )-old_tally_sizes.append(0) # makes the edge cases work properly-- # split the other tallies- for i in range(k) + range(k + 1, n + 1):++ # split all tallies+ for i in range(n + 1):self.play(Transform(grouped_outcomes[i][0],grouped_target_outcomes[i][0][old_tally_sizes[i - 1]:]@@ -857,7 +854,7 @@ class BrickRowScene(PiCreatureScene):grouped_target_outcomes[i + 1][0][:old_tally_sizes[i]]))-+ returnself.wait()@@ -921,6 +918,7 @@ class BrickRowScene(PiCreatureScene):self.play(FadeOut(new_tallies))self.clear()+ self.row = BrickRow(3)self.add(randy, self.row)@@ -950,6 +948,227 @@ class BrickRowScene(PiCreatureScene):+class ShowProbsInBrickRow3(BrickRowScene):++ def construct(self):++ randy = self.get_primary_pi_creature()+ randy = randy.scale(0.5).move_to(3*DOWN + 6*LEFT)+ #self.add(randy)+ self.row = BrickRow(3, height = 2, width = 10)+ self.wait()++ self.add(self.row)++ tallies = VGroup()+ for (i, rect) in enumerate(self.row.get_rects_for_level(3)):+ tally = TallyStack(3-i, i, show_decimals = False)+ tally.move_to(rect)+ tallies.add(tally)++ self.add(tallies)+ self.wait(6)++ braces = VGroup(*[Brace(rect, UP) for rect in self.row.rects])+ counts = [choose(3, i) for i in range(4)]+ probs = VGroup(*[TexMobject("{" + str(k) + "\over 8}") for k in counts])+ for (brace, prob) in zip(braces, probs):+ prob.next_to(brace, UP)++ self.wait()+ self.play(+ LaggedStart(ShowCreation, braces, run_time = 3),+ LaggedStart(Write, probs, run_time = 3)+ )+ self.wait()++ self.play(FadeOut(braces),FadeOut(probs))+++++class ShowOutcomesInBrickRow4(BrickRowScene):++ def construct(self):++ randy = self.get_primary_pi_creature()+ randy = randy.scale(0.5).move_to(3*DOWN + 6*LEFT)+ #self.add(randy)+ self.row = BrickRow(3, height = 2, width = 10)++ previous_row = self.row.copy()+ v = 1.25 * self.row.height * UP+ self.play(+ previous_row.shift, v,+ )++ self.add(self.row)+ self.add(previous_row)+++++ self.wait()+ previous_outcomes = previous_row.get_outcome_rects_for_level(3,+ with_labels = True, inset = True)++ previous_outcomes_copy = previous_outcomes.copy()++++ self.play(+ LaggedStart(FadeIn, previous_outcomes),+ LaggedStart(FadeIn, previous_outcomes_copy),+ )++ self.wait()++ new_outcomes = self.row.get_outcome_rects_for_level(4,+ with_labels = True, inset = True)+ # remove each last coin+++ new_outcomes_left = VGroup(+ new_outcomes[0],+ new_outcomes[2],+ new_outcomes[3],+ new_outcomes[4],+ new_outcomes[8],+ new_outcomes[9],+ new_outcomes[10],+ new_outcomes[14]+ )+ new_outcomes_right = VGroup(+ new_outcomes[1],+ new_outcomes[5],+ new_outcomes[6],+ new_outcomes[7],+ new_outcomes[11],+ new_outcomes[12],+ new_outcomes[13],+ new_outcomes[15]+ )+ heads_labels = VGroup(*[outcome.label[-1] for outcome in new_outcomes_left])+ tails_labels = VGroup(*[outcome.label[-1] for outcome in new_outcomes_right])+ heads_labels.save_state()+ tails_labels.save_state()+ for outcome in new_outcomes:+ outcome.label[-1].fade(1)++ run_time = 0.5+ self.play(Transform(previous_outcomes[0], new_outcomes_left[0], run_time = run_time))+ self.play(Transform(previous_outcomes[1:4], new_outcomes_left[1:4], run_time = run_time))+ self.play(Transform(previous_outcomes[4:7], new_outcomes_left[4:7], run_time = run_time))+ self.play(Transform(previous_outcomes[7], new_outcomes_left[7], run_time = run_time))+++ self.play(heads_labels.restore)+++ self.play(Transform(previous_outcomes_copy[0], new_outcomes_right[0], run_time = run_time))+ self.play(Transform(previous_outcomes_copy[1:4], new_outcomes_right[1:4], run_time = run_time))+ self.play(Transform(previous_outcomes_copy[4:7], new_outcomes_right[4:7], run_time = run_time))+ self.play(Transform(previous_outcomes_copy[7], new_outcomes_right[7], run_time = run_time))+++ self.play(tails_labels.restore)+++ self.wait()++ anims = [FadeOut(previous_outcomes),FadeOut(previous_outcomes_copy)]++ for outcome in new_outcomes_left:+ anims.append(FadeOut(outcome.label[-1]))+ for outcome in new_outcomes_right:+ anims.append(FadeOut(outcome.label[-1]))++ self.play(*anims)++ self.wait()++++++class SplitTalliesIntoBrickRow4(BrickRowScene):++ def construct(self):++ randy = self.get_primary_pi_creature()+ randy = randy.scale(0.5).move_to(3*DOWN + 6*LEFT)+ #self.add(randy)+ self.row = BrickRow(3, height = 2, width = 10)++ previous_row = self.row.copy()+ v = 1.25 * self.row.height * UP+ self.play(+ previous_row.shift, v,+ )++ tallies = VGroup()+ for (i, rect) in enumerate(previous_row.get_rects_for_level(3)):+ tally = TallyStack(3-i, i, show_decimals = True)+ tally.move_to(rect)+ tallies.add(tally)++ moving_tallies_left = tallies.copy()+ moving_tallies_right = tallies.copy()++ self.add(self.row, previous_row)+ self.add_foreground_mobject(tallies)+ self.add_foreground_mobject(moving_tallies_left)+ self.add_foreground_mobject(moving_tallies_right)+++ self.play(SplitRectsInBrickWall(self.row))++ anims = []+ for (tally, rect) in zip(moving_tallies_left, previous_row.rects):+ anims.append(tally.move_to)+ anims.append(rect.get_center() + rect.get_width() * 0.25 * LEFT)++ self.play(*anims)++ new_tallies_left = VGroup()+ for (i, tally) in enumerate(moving_tallies_left):+ new_tally = TallyStack(4-i,i, with_labels = True)+ new_tally.move_to(tally)+ new_tallies_left.add(new_tally)++ self.play(Transform(moving_tallies_left, new_tallies_left))++ anims = []+ for (tally, rect) in zip(moving_tallies_right, previous_row.rects):+ anims.append(tally.move_to)+ anims.append(rect.get_center() + rect.get_width() * 0.25 * RIGHT)++ self.play(*anims)++ new_tallies_right = VGroup()+ for (i, tally) in enumerate(moving_tallies_right):+ new_tally = TallyStack(3-i,i+1, with_labels = True)+ new_tally.move_to(tally)+ new_tallies_right.add(new_tally)++ self.play(Transform(moving_tallies_right, new_tallies_right))+++ hypothetical_new_row = BrickRow(4, height = 2, width = 10)+ anims = []+ for (tally, rect) in zip(moving_tallies_left[1:], hypothetical_new_row.rects[1:-1]):+ anims.append(tally.move_to)+ anims.append(rect)+ for (tally, rect) in zip(moving_tallies_right[:-1], hypothetical_new_row.rects[1:-1]):+ anims.append(tally.move_to)+ anims.append(rect)+ self.play(*anims)+ self.wait()+ self.row = self.merge_rects_by_subdiv(self.row)+ self.wait()+ self.row = self.merge_rects_by_coloring(self.row)+ self.wait()+diff --git a/active_projects/eop/chapter1/morph_brick_row_into_histogram.py b/active_projects/eop/chapter1/morph_brick_row_into_histogram.pyindex ac924c0ee..ff5e83044 100644--- a/active_projects/eop/chapter1/morph_brick_row_into_histogram.py+++ b/active_projects/eop/chapter1/morph_brick_row_into_histogram.py@@ -42,15 +42,16 @@ class GenericMorphBrickRowIntoHistogram(Scene):rect.set_stroke(color = WHITE, width = 3)self.wait()- self.play(self.row.rects.space_out_submobjects, {"factor" : 1.3})+ self.play(+ self.row.rects.space_out_submobjects, {"factor" : 1.3},+ FadeOut(tallies)+ )self.wait()anims = []for brick in self.row.rects:anims.append(brick.rotate)anims.append(TAU/4)- if self.show_tallies:- anims.append(FadeOut(tallies))self.play(*anims)self.wait()@@ -74,6 +75,7 @@ class GenericMorphBrickRowIntoHistogram(Scene):self.wait()+class MorphBrickRowIntoHistogram3(GenericMorphBrickRowIntoHistogram):CONFIG = {@@ -87,6 +89,8 @@ class MorphBrickRowIntoHistogram3(GenericMorphBrickRowIntoHistogram):def construct(self):++super(MorphBrickRowIntoHistogram3,self).construct()diff --git a/active_projects/eop/chapter1/prob_dist_visuals.py b/active_projects/eop/chapter1/prob_dist_visuals.pyindex 243024034..513c94c20 100644--- a/active_projects/eop/chapter1/prob_dist_visuals.py+++ b/active_projects/eop/chapter1/prob_dist_visuals.py@@ -40,7 +40,7 @@ class ProbabilityDistributions(PiCreatureScene):self.add(unit_rect, rain_rect, sun_rect)- rain = SVGMobject(file_name = "rain").scale(0.35)+ rain = SVGMobject(file_name = "rain").scale(0.25)sun = SVGMobject(file_name = "sun").scale(0.35)rain.flip().move_to(rain_rect)@@ -156,7 +156,7 @@ class ProbabilityDistributions(PiCreatureScene):FadeOut(p_sun_whole_label),)-+ self.wait(3)# DOUBLE DICE THROW@@ -193,7 +193,6 @@ class ProbabilityDistributions(PiCreatureScene):# FadeIn(dice_unit_rect),# FadeIn(dice_table.rows)# )- self.add(dice_unit_rect, dice_table_rows)for (cell, label) in zip(dice_table.cells, dice_table.labels):cell.add(label)@@ -202,9 +201,13 @@ class ProbabilityDistributions(PiCreatureScene):# LaggedStart(FadeIn, dice_table_grouped_cells,# lag_ratio = lag_ratio, run_time = run_time)# )- self.add(dice_table_grouped_cells)+ self.play(+ FadeIn(dice_table_grouped_cells),+ FadeIn(dice_unit_rect),+ FadeIn(dice_table.rows)+ )- self.wait()+ self.wait(3)self.play(@@ -212,18 +215,19 @@ class ProbabilityDistributions(PiCreatureScene):rate_func=there_and_back_with_pause,run_time=run_time)+ dice_table.add(dice_unit_rect)+ dice_table_target = dice_table.copy()+ dice_table_target.scale(0.5).to_corner(UR, buff = LARGE_BUFF)+ dice_table_target.shift(0.4*UP)++ self.play(Transform(dice_table, dice_table_target))self.play(FadeOut(dice_table.rows),FadeOut(dice_unit_rect),)-- dice_table_target = dice_table.copy()- dice_table_target.scale(0.5).to_corner(UR, buff = MED_LARGE_BUFF)-- self.play(Transform(dice_table, dice_table_target))- self.wait()+ self.wait(3)# TITLE@@ -236,16 +240,17 @@ class ProbabilityDistributions(PiCreatureScene):ShowCreation(text_rect))- self.wait()+ self.wait(3)# COIN FLIP- coin_flip_rect = BrickRow(3, height = 2, width = 10)+ brick_row = BrickRow(3, height = 2, width = 10)+ coin_flip_rect = VGroup(brick_row)tallies = VGroup()- for (i, brick) in enumerate(coin_flip_rect.rects):+ for (i, brick) in enumerate(brick_row.rects):tally = TallyStack(3 - i, i)tally.move_to(brick)tallies.add(tally)@@ -257,7 +262,7 @@ class ProbabilityDistributions(PiCreatureScene):counts = [1, 3, 3, 1]braces = VGroup()labels = VGroup()- for (rect, count) in zip(coin_flip_rect.rects, counts):+ for (rect, count) in zip(brick_row.rects, counts):label = TexMobject("{" + str(count) + "\over 8}").scale(0.5)brace = Brace(rect, DOWN)label.next_to(brace, DOWN)@@ -271,15 +276,13 @@ class ProbabilityDistributions(PiCreatureScene):coin_flip_rect.add(braces, labels)- coin_flip_rect.target = coin_flip_rect.copy().scale(0.6)- coin_flip_rect.target.to_corner(UR, buff = MED_LARGE_BUFF)- coin_flip_rect.target.shift(DOWN)+ self.wait(6)- self.wait()-- outcomes = coin_flip_rect.get_outcome_rects_for_level(3, with_labels = True,+ outcomes = brick_row.get_outcome_rects_for_level(3, with_labels = True,inset = True)+ outcomes.scale(0.65)+ outcomes.move_to(brick_row.get_center())outcome_braces = VGroup(*[Brace(outcome, DOWN) for outcome in outcomes])@@ -297,7 +300,8 @@ class ProbabilityDistributions(PiCreatureScene):FadeIn(outcome_labels))- self.wait()++ self.wait(10)diff --git a/active_projects/eop/chapter1/quiz_result.py b/active_projects/eop/chapter1/quiz_result.pyindex 3488efea6..c6a85b309 100644--- a/active_projects/eop/chapter1/quiz_result.py+++ b/active_projects/eop/chapter1/quiz_result.py@@ -71,9 +71,11 @@ class QuizResult(PiCreatureScene):all_quizzes.add(quiz_copy)master_quiz = get_example_quiz()- self.play(ShowCreation(master_quiz))+ self.play(ShowCreation(master_quiz), run_time = 2)+ self.wait()self.play(Transform(master_quiz, all_quizzes[0]))-+ self.wait()+self.play(LaggedStart(FadeIn,all_quizzes))grades_mob = VGroup()@@ -83,6 +85,7 @@ class QuizResult(PiCreatureScene):grades_mob.add(grade_mob)self.remove(master_quiz)+ self.wait()self.play(FadeOut(all_quizzes),FadeIn(grades_mob)@@ -99,13 +102,53 @@ class QuizResult(PiCreatureScene):slot.scale(0.5).move_to(quiz)students_points_mob.add(slot)+ self.wait()self.play(#all_students.fade, 0,FadeOut(grades_mob),FadeIn(students_points_mob))+ all_students.save_state()+ students_points_mob.save_state()+ self.wait()+ randy = all_students[0]+ morty = all_students[nb_students_y]+ all_other_students = VGroup(*all_students)+ all_other_students.remove(randy, morty)+ randy_points = students_points_mob[0]+ morty_points = students_points_mob[nb_students_y]+ all_other_points = VGroup(*students_points_mob)+ all_other_points.remove(randy_points, morty_points)+ self.play(+ all_other_students.fade, 0.8,+ all_other_points.fade, 0.8,+ )+ self.wait()+ scale = 1.5+ self.play(randy_points.scale,scale)+ self.play(randy_points.scale,1.0/scale, morty_points.scale,scale)+ self.play(morty_points.scale,1.0/scale)++ self.wait()+ self.play(+ all_students.restore,+ students_points_mob.restore,+ )+ self.wait()+ anims = []+ for points in students_points_mob:+ anims.append(points.scale)+ anims.append(scale)+ self.play(*anims)++ self.wait()+ anims = []+ for points in students_points_mob:+ anims.append(points.scale)+ anims.append(1.0/scale)+ self.play(*anims)anims = []anchor_point = 3 * DOWN + 1 * LEFT@@ -114,6 +157,7 @@ class QuizResult(PiCreatureScene):anims.append(anchor_point + grade * RIGHT + grades_count * UP)anims.append(FadeOut(students_points_mob))+ self.wait()self.play(*anims)grade_labels = VGroup()@@ -125,6 +169,7 @@ class QuizResult(PiCreatureScene):out_of_label = TextMobject("out of 3", color = highlight_color)out_of_label.next_to(grade_labels, RIGHT, buff = MED_LARGE_BUFF)grade_labels.add(out_of_label)+ self.wait()self.play(Write(grade_labels))grade_hist = Histogram(@@ -138,6 +183,7 @@ class QuizResult(PiCreatureScene):)grade_hist.move_to(all_students)+ self.wait()self.play(FadeIn(grade_hist),FadeOut(all_students)@@ -145,12 +191,13 @@ class QuizResult(PiCreatureScene):nb_students_label = TextMobject("\# of students", color = highlight_color)- nb_students_label.move_to(5 * LEFT + 2 * UP)+ nb_students_label.move_to(5 * RIGHT + 1 * UP)arrows = VGroup(*[- Arrow(nb_students_label.get_right(), grade_hist.bars[i].get_center(),+ Arrow(nb_students_label.get_left(), grade_hist.bars[i].get_center(),color = highlight_color)for i in range(4)])+ self.wait()self.play(Write(nb_students_label), LaggedStart(GrowArrow,arrows))percentage_label = TextMobject("\% of students", color = highlight_color)@@ -167,6 +214,7 @@ class QuizResult(PiCreatureScene):new_label.move_to(label)anims.append(Transform(label, new_label))anims.append(ReplacementTransform(nb_students_label, percentage_label))+ self.wait()self.play(*anims)self.remove(all_quizzes)@@ -177,10 +225,12 @@ class QuizResult(PiCreatureScene):pi.move_to(x * RIGHT + y * UP)all_students.scale(0.8)all_students.to_corner(DOWN + LEFT)+ self.wait()self.play(FadeIn(all_students))prob_label = TextMobject("probability", color = highlight_color)prob_label.move_to(percentage_label)+ self.wait()self.play(all_students[8].set_color, MAROON_E,#all_students[:8].fade, 0.6,@@ -188,6 +238,7 @@ class QuizResult(PiCreatureScene):ReplacementTransform(percentage_label, prob_label))+ self.wait()self.play(FadeOut(prob_label),FadeOut(arrows)@@ -210,6 +261,7 @@ class QuizResult(PiCreatureScene):rate_func = linear)+ self.wait()for i in range(3):self.play(flash_hist, flash_class)self.remove(flash_hist.prototype_cell)diff --git a/active_projects/eop/reusables/brick_row.py b/active_projects/eop/reusables/brick_row.pyindex 1e240d352..38bf603d1 100644--- a/active_projects/eop/reusables/brick_row.py+++ b/active_projects/eop/reusables/brick_row.py@@ -179,7 +179,6 @@ class BrickRow(VMobject):-class SplitRectsInBrickWall(AnimationGroup):def __init__(self, mobject, **kwargs):