Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

bug in debugging method

Ben Hambrecht85808eb905c8
diff --git a/active_projects/eop/chapter1.py b/active_projects/eop/chapter1.py
index 78fe4c7c4..047262ac2 100644
--- a/active_projects/eop/chapter1.py
+++ b/active_projects/eop/chapter1.py
@@ -452,7 +452,7 @@ class Introduction(TeacherStudentsScene):
def construct(self):
- self.wait()
+ self.wait(5)
self.change_student_modes(
"confused", "frustrated", "dejected",
@@ -462,17 +462,9 @@ class Introduction(TeacherStudentsScene):
self.wait()
- self.get_teacher().change_mode("hooray")
+ self.get_teacher().change_mode("raise_right_hand")
self.wait()
- self.play(
- self.get_teacher().change_mode, "raise_right_hand",
- *[
- ApplyMethod(pi.change, "pondering", {"look_at_arg" : UP + 2 * LEFT})
- for pi in self.get_students()
- ]
- )
-
self.wait(30)
# put examples here in video editor
@@ -1057,50 +1049,81 @@ class ShowUncertainty2(Scene):
self.throw_darts(1000,5)
+SICKLY_GREEN = "#9BBD37"
+class SicklyPiCreature(PiCreature):
+ CONFIG = {
+ "sick_color": SICKLY_GREEN
+ }
-class ShowUncertainty3(Scene):
+ def get_slightly_sick(self):
- def construct(self):
+ self.save_state()
+ self.set_color(self.sick_color)
- randy = CoinFlippingPiCreature(color = MAROON_E)
- randy.scale(0.5).to_edge(LEFT + DOWN)
+ def get_sick(self):
- heads = tails = 0
- tally = TallyStack(heads, tails, anchor = ORIGIN)
+ self.get_slightly_sick()
+ self.change_mode("sick")
- nb_flips = 10
+ def get_better(self):
+ self.restore()
- flips = np.random.randint(2, size = nb_flips)
- for i in range(nb_flips):
+class RandyIsSickOrNot(Scene):
- self.play(FlipCoin(randy))
- self.wait(0.5)
- flip = flips[i]
- if flip == 0:
- heads += 1
- elif flip == 1:
- tails += 1
- else:
- raise Exception("That side does not exist on this coin")
+ def construct(self):
+ title = TextMobject("1 in 200")
+ title.to_edge(UP)
- new_tally = TallyStack(heads, tails, anchor = ORIGIN)
+
+ randy = SicklyPiCreature()
+ randy.scale_to_fit_height(3)
+ randy.move_to(2*LEFT)
+ randy.change_mode("plain")
+ randy.set_color(BLUE)
+ randy.save_state()
- if tally.nb_heads == 0 and new_tally.nb_heads == 1:
- self.play(FadeIn(new_tally.heads_stack))
- elif tally.nb_tails == 0 and new_tally.nb_tails == 1:
- self.play(FadeIn(new_tally.tails_stack))
- else:
- self.play(Transform(tally, new_tally))
+ self.add(randy)
- tally = new_tally
+ p_sick = TexMobject("p(","\\text{sick}",") = 0.5\%").scale(1.7)
+ p_sick.set_color_by_tex("sick", SICKLY_GREEN)
+ p_sick.next_to(randy, UP, buff = LARGE_BUFF)
+ self.add(p_sick)
+ self.wait()
+
+ self.play(
+ ApplyMethod(randy.get_slightly_sick, rate_func = there_and_back)
+ )
+ self.play(Blink(randy))
+ self.wait(2)
+
+ self.play(
+ ApplyMethod(randy.get_sick)
+ )
+ self.play(Blink(randy))
+ self.wait()
+
+ self.play(randy.get_better)
+
+ self.play(
+ ApplyMethod(randy.get_slightly_sick, rate_func = there_and_back)
+ )
+ self.play(Blink(randy))
+ self.wait(0.5)
+
+ self.play(
+ ApplyMethod(randy.get_sick)
+ )
+
+ self.play(Blink(randy))
+ self.play(randy.get_better)
+ self.wait(3)
-SICKLY_GREEN = "#9BBD37"
class OneIn200HasDisease(Scene):
def construct(self):
@@ -1129,25 +1152,101 @@ class OneIn200HasDisease(Scene):
self.add(randy)
- p_sick = TexMobject("p(","\\text{sick}",") = 0.5\%")
- p_sick.set_color_by_tex("sick", SICKLY_GREEN)
- p_sick.next_to(randy, RIGHT+UP)
- self.add(p_sick)
+ #p_sick = TexMobject("p(","\\text{sick}",") = 0.5\%")
+ #p_sick.set_color_by_tex("sick", SICKLY_GREEN)
+ #p_sick.next_to(randy, RIGHT+UP)
+ #self.add(p_sick)
self.wait()
+
self.play(
randy.change_mode, "sick",
randy.set_color, SICKLY_GREEN
)
self.play(Blink(randy))
self.play(randy.restore)
+ self.wait()
self.play(
- FadeOut(p_sick),
Write(title),
LaggedStart(FadeIn, all_creatures, run_time = 3)
)
self.wait()
+class RandyFlipsAndStacks(Scene):
+
+ def construct(self):
+
+ randy = CoinFlippingPiCreature(color = MAROON_E)
+ randy.scale(0.5).to_edge(LEFT + DOWN)
+
+ heads = tails = 0
+ tally = TallyStack(heads, tails, anchor = ORIGIN)
+
+ nb_flips = 10
+
+ flips = np.random.randint(2, size = nb_flips)
+
+ for i in range(nb_flips):
+
+ self.play(FlipCoin(randy))
+ self.wait(0.5)
+
+ flip = flips[i]
+ if flip == 0:
+ heads += 1
+ elif flip == 1:
+ tails += 1
+ else:
+ raise Exception("That side does not exist on this coin")
+
+ new_tally = TallyStack(heads, tails, anchor = ORIGIN)
+
+ if tally.nb_heads == 0 and new_tally.nb_heads == 1:
+ self.play(FadeIn(new_tally.heads_stack))
+ elif tally.nb_tails == 0 and new_tally.nb_tails == 1:
+ self.play(FadeIn(new_tally.tails_stack))
+ else:
+ self.play(Transform(tally, new_tally))
+
+ tally = new_tally
+
+
+
+class TwoDiceTable(Scene):
+
+ def construct(self):
+
+ table = VGroup()
+ cell_size = 1
+ colors = np.random.permutation(color_gradient([RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE], 13))
+
+ for i in range(1,7):
+ for j in range(1,7):
+ cell = Square(side_length = cell_size)
+ cell.set_fill(color = colors[i+j], opacity = 0.8)
+ label = Integer(i+j)
+ label.move_to(cell)
+ cell.add(label)
+ cell.move_to(i*cell_size*RIGHT + j*cell_size*DOWN)
+ table.add(cell)
+
+ table.center()
+ self.add(table)
+
+ row1 = RowOfDice().match_width(table)
+ print row1.is_subpath
+ row2 = row1.copy().rotate(-TAU/4)
+ print row2.is_subpath
+ row1.next_to(table, UP)
+ row2.next_to(table, LEFT)
+ self.add(row1, row2)
+
+
+
+
+
+
+
class BrickRow(VMobject):
@@ -1344,7 +1443,7 @@ class JustFlipping(Scene):
def construct(self):
- randy = CoinFlippingPiCreature()
+ randy = CoinFlippingPiCreature().shift(2 * DOWN)
self.add(randy)
self.wait(2)
@@ -1355,6 +1454,46 @@ class JustFlipping(Scene):
+class JustFlippingWithResults(Scene):
+
+ def construct(self):
+
+ randy = CoinFlippingPiCreature().shift(2 * DOWN)
+ self.add(randy)
+
+ self.wait(2)
+
+ for i in range(10):
+ self.wait()
+ self.play(FlipCoin(randy))
+ result = random.choice(["H", "T"])
+ if result == "H":
+ coin = UprightHeads().scale(3)
+ else:
+ coin = UprightTails().scale(3)
+ coin.move_to(2 * UP + 2.5 * LEFT + i * 0.6 * RIGHT)
+ self.play(FadeIn(coin))
+
+
+
+class WhatDoesItReallyMean(TeacherStudentsScene):
+
+ CONFIG = {
+ "default_pi_creature_kwargs": {
+ "color": MAROON_E,
+ "flip_at_start": True,
+ },
+ }
+
+ def construct(self):
+
+ student_q = TextMobject("What does", "``probability''", "\emph{actually}", "mean?")
+ student_q.set_color_by_tex("probability", YELLOW)
+ self.student_says(student_q, target_mode = "sassy")
+ self.wait()
+ self.teacher_says("Don't worry -- philosophy can come later!")
+ self.wait()
+
class BrickRowScene(Scene):
@@ -1648,7 +1787,7 @@ class BrickRowScene(Scene):
def construct(self):
- #self.force_skipping()
+ self.force_skipping()
randy = CoinFlippingPiCreature()
randy = randy.scale(0.5).move_to(3*DOWN + 6*LEFT)
@@ -1764,54 +1903,6 @@ class BrickRowScene(Scene):
# self.add_foreground_mobject(self.decimals)
- # # # # # # # #
- # FOURTH FLIP #
- # # # # # # # #
-
- # self.play(FlipCoin(randy))
-
- # self.wait()
-
- # self.play(
- # SplitRectsInBrickWall(self.row)
- # )
- # self.wait()
-
- # self.add_foreground_mobject(self.tallies[-1])
- # # this tweaks an undesirable overlap in the next animation
- # self.split_tallies_at_once(direction = LEFT)
- # self.wait()
- # self.merge_rects_by_subdiv()
- # self.wait()
- # self.merge_tallies(direction = LEFT)
- # self.merge_rects_by_coloring()
- # self.merge_decimals()
- # self.wait()
-
-
- # # # # # # # #
- # FIFTH FLIP #
- # # # # # # # #
-
- # self.play(FlipCoin(randy))
-
- # self.wait()
-
- # self.play(
- # SplitRectsInBrickWall(self.row)
- # )
- # self.wait()
-
- # self.split_tallies_at_once(direction = LEFT)
- # self.wait()
- # self.merge_rects_by_subdiv()
- # self.wait()
- # self.merge_tallies(direction = LEFT)
- # self.merge_rects_by_coloring()
- # self.merge_decimals()
- # self.wait()
-
-
# # # # # # # # # # # # # #
# # FOURTH FLIP IN DETAIL #
# # # # # # # # # # # # # #
@@ -1890,7 +1981,7 @@ class BrickRowScene(Scene):
# show how the outcomes in one tally split into two copies
# going into the neighboring tallies
- self.revert_to_original_skipping_status()
+ #self.revert_to_original_skipping_status()
target_outcomes = self.row.get_outcome_rects_for_level(n + 1, with_labels = False)
grouped_target_outcomes = VGroup()
@@ -1995,6 +2086,117 @@ class BrickRowScene(Scene):
# self.add_foreground_mobject(new_decimals)
+ # # # # # # # #
+ # FIFTH FLIP #
+ # # # # # # # #
+
+ # self.remove(
+ # grouped_outcomes,
+ # grouped_outcomes_copy,
+ # grouped_target_outcomes,
+ # target_outcomes,
+ # outcomes,
+ # previous_row,
+ # original_grouped_outcomes)
+ self.clear()
+ self.add(randy, self.row)
+ self.row.shift(0.5 * UP)
+
+
+ self.merge_rects_by_coloring()
+
+ self.revert_to_original_skipping_status()
+
+ for i in range(3):
+
+ self.play(FlipCoin(randy))
+
+ self.wait()
+
+ self.play(
+ SplitRectsInBrickWall(self.row)
+ )
+ self.wait()
+
+ #self.split_tallies_at_once(direction = LEFT)
+ self.wait()
+ self.merge_rects_by_subdiv()
+ self.wait()
+ #self.merge_tallies(direction = LEFT)
+ self.merge_rects_by_coloring()
+ #self.merge_decimals()
+ self.wait()
+
+class LevelsOfDetailInBrickRow(BrickRowScene):
+
+ def construct(self):
+
+ self.force_skipping()
+
+ randy = CoinFlippingPiCreature()
+ randy = randy.scale(0.5).move_to(3*DOWN + 6*LEFT)
+ self.add(randy)
+ self.row = BrickRow(1, height = 2, width = 10)
+
+ #self.decimals = VGroup()
+
+ self.play(FlipCoin(randy),
+ FadeIn(self.row))
+
+
+ self.wait()
+
+ # put tallies on top
+
+ self.tallies = VGroup(*[
+ TallyStack(1 - i, i) for i in range(2)
+ ])
+ for (tally, rect) in zip(self.tallies, self.row.rects):
+ new_anchor = rect.get_center() + 1.2 * 0.5 * rect.get_height() * UP
+ tally.move_anchor_to(new_anchor)
+ self.play(FadeIn(tally))
+
+ self.add_foreground_mobject(self.tallies)
+ self.wait()
+
+
+ # # # # # # # #
+ # SECOND FLIP #
+ # # # # # # # #
+
+
+
+ self.play(FlipCoin(randy))
+ self.wait()
+
+
+ self.play(
+ SplitRectsInBrickWall(self.row)
+ )
+ self.wait()
+
+ # show individual outcomes
+ outcomes = self.row.get_outcome_rects_for_level(2, with_labels = True)
+ self.play(
+ LaggedStart(FadeIn, outcomes)
+ )
+ self.wait()
+ self.play(
+ LaggedStart(FadeOut, outcomes)
+ )
+
+ self.split_tallies_in_two_steps()
+ self.wait()
+ self.merge_rects_by_subdiv()
+ self.wait()
+ self.merge_tallies()
+ self.merge_rects_by_coloring()
+ self.wait()
+ self.move_tallies_on_top()
+
+
+
+
class OutlineableBars(VGroup):
CONFIG = {
@@ -2123,13 +2325,13 @@ class MorphBrickRowIntoHistogram3(GenericMorphBrickRowIntoHistogram):
label.next_to(self.bar_anchors[i], DOWN)
x_labels.add(label)
- nb_heads_label = TextMobject("\# of heads")
- nb_heads_label.next_to(x_labels[-1], RIGHT, MED_LARGE_BUFF)
+ nb_tails_label = TextMobject("\# of tails")
+ nb_tails_label.next_to(x_labels[-1], RIGHT, MED_LARGE_BUFF)
self.play(
FadeIn(x_axis),
FadeIn(x_labels),
- FadeIn(nb_heads_label)
+ FadeIn(nb_tails_label)
)
@@ -2201,13 +2403,13 @@ class MorphBrickRowIntoHistogram20(GenericMorphBrickRowIntoHistogram):
label.next_to(self.bar_anchors[i], DOWN)
x_labels.add(label)
- nb_heads_label = TextMobject("\# of heads")
- nb_heads_label.next_to(x_labels[-1], RIGHT, MED_LARGE_BUFF)
+ nb_tails_label = TextMobject("\# of heads")
+ nb_tails_label.next_to(x_labels[-1], RIGHT, MED_LARGE_BUFF)
self.play(
FadeIn(x_axis),
FadeIn(x_labels),
- FadeIn(nb_heads_label)
+ FadeIn(nb_tails_label)
)
# draw y-guides
diff --git a/mobject/mobject.py b/mobject/mobject.py
index 123b52067..235ed515c 100644
--- a/mobject/mobject.py
+++ b/mobject/mobject.py
@@ -767,7 +767,7 @@ class Mobject(Container):
"""For debugging purposes"""
print "\t" * n_tabs, self, id(self)
for submob in self.submobjects:
- submob.print_mobject_family(n_tabs + 1)
+ submob.print_submobject_family(n_tabs + 1)
# Alignment
def align_data(self, mobject):