mirror of
https://github.com/3b1b/manim.git
synced 2025-09-19 04:41:56 +00:00
last tweaks for chapter 1
This commit is contained in:
parent
240b9b8e44
commit
1456c8cb98
10 changed files with 208 additions and 41 deletions
|
@ -312,31 +312,57 @@ class BrickRowScene(PiCreatureScene):
|
|||
new_tails[i].shift(COIN_SEQUENCE_SPACING * DOWN)
|
||||
self.play(FadeIn(new_tails))
|
||||
|
||||
decimal_tallies = VGroup()
|
||||
# introduce notion of tallies
|
||||
for (i, rect) in enumerate(self.row.get_rects_for_level(2)):
|
||||
tally = DecimalTally(2-i, i)
|
||||
tally.next_to(rect, UP)
|
||||
decimal_tallies.add(tally)
|
||||
self.play(FadeIn(tally))
|
||||
self.wait()
|
||||
|
||||
self.add_foreground_mobject(single_flip_labels)
|
||||
self.add_foreground_mobject(new_heads)
|
||||
self.add_foreground_mobject(single_flip_labels_copy)
|
||||
self.add_foreground_mobject(new_tails)
|
||||
|
||||
# show individual outcomes
|
||||
outcomes = self.row.get_outcome_rects_for_level(2, with_labels = False)
|
||||
# get individual outcomes
|
||||
outcomes = self.row.get_outcome_rects_for_level(2, with_labels = False,
|
||||
inset = True)
|
||||
grouped_outcomes = VGroup(outcomes[0], outcomes[1:3], outcomes[3])
|
||||
|
||||
decimal_tallies = VGroup()
|
||||
# introduce notion of tallies
|
||||
rects = self.row.get_rects_for_level(2)
|
||||
|
||||
rect = rects[0]
|
||||
tally = DecimalTally(2,0)
|
||||
tally.next_to(rect, UP)
|
||||
decimal_tallies.add(tally)
|
||||
self.play(
|
||||
LaggedStart(FadeIn, outcomes)
|
||||
FadeIn(tally),
|
||||
FadeIn(grouped_outcomes[0])
|
||||
)
|
||||
self.wait()
|
||||
|
||||
rect = rects[1]
|
||||
tally = DecimalTally(1,1)
|
||||
tally.next_to(rect, UP)
|
||||
decimal_tallies.add(tally)
|
||||
self.play(
|
||||
LaggedStart(FadeOut, outcomes),
|
||||
FadeIn(tally),
|
||||
FadeOut(grouped_outcomes[0]),
|
||||
FadeIn(grouped_outcomes[1])
|
||||
)
|
||||
self.wait()
|
||||
|
||||
rect = rects[2]
|
||||
tally = DecimalTally(0,2)
|
||||
tally.next_to(rect, UP)
|
||||
decimal_tallies.add(tally)
|
||||
self.play(
|
||||
FadeIn(tally),
|
||||
FadeOut(grouped_outcomes[1]),
|
||||
FadeIn(grouped_outcomes[2])
|
||||
)
|
||||
self.wait()
|
||||
|
||||
self.play(
|
||||
FadeOut(grouped_outcomes[2])
|
||||
)
|
||||
self.wait()
|
||||
|
||||
self.wait()
|
||||
self.play(
|
||||
FadeOut(single_flip_labels),
|
||||
|
@ -346,7 +372,6 @@ class BrickRowScene(PiCreatureScene):
|
|||
)
|
||||
self.wait()
|
||||
|
||||
|
||||
self.tallies = VGroup()
|
||||
for (i, rect) in enumerate(self.row.get_rects_for_level(2)):
|
||||
tally = TallyStack(2-i, i, show_decimals = False)
|
||||
|
@ -386,7 +411,8 @@ class BrickRowScene(PiCreatureScene):
|
|||
# CALLBACK TO SEQUENCES #
|
||||
# # # # # # # # # # # # #
|
||||
|
||||
outcomes = self.row.get_outcome_rects_for_level(2, with_labels = True)
|
||||
outcomes = self.row.get_outcome_rects_for_level(2, with_labels = True,
|
||||
inset = True)
|
||||
subdivs = self.row.get_sequence_subdivs_for_level(2)
|
||||
self.play(
|
||||
FadeIn(outcomes),
|
||||
|
@ -396,7 +422,8 @@ class BrickRowScene(PiCreatureScene):
|
|||
|
||||
self.wait()
|
||||
|
||||
rect_to_dice = outcomes[1]
|
||||
rect_to_dice = self.row.get_outcome_rects_for_level(2, with_labels = False,
|
||||
inset = False)[1]
|
||||
N = 10
|
||||
dice_width = rect_to_dice.get_width()/N
|
||||
dice_height = rect_to_dice.get_height()/N
|
||||
|
@ -419,9 +446,8 @@ class BrickRowScene(PiCreatureScene):
|
|||
|
||||
self.play(
|
||||
LaggedStart(FadeIn, all_dice),
|
||||
FadeOut(rect_to_dice.label)
|
||||
FadeOut(outcomes[1])
|
||||
)
|
||||
|
||||
self.wait()
|
||||
|
||||
table = Ellipse(width = 1.5, height = 1)
|
||||
|
@ -455,7 +481,6 @@ class BrickRowScene(PiCreatureScene):
|
|||
run_time = 0.05)
|
||||
)
|
||||
|
||||
|
||||
self.wait()
|
||||
|
||||
self.play(
|
||||
|
@ -513,14 +538,17 @@ class BrickRowScene(PiCreatureScene):
|
|||
self.clear()
|
||||
self.add(randy, self.row, old_row)
|
||||
self.add_foreground_mobject(self.tallies)
|
||||
self.add_foreground_mobject(self.tallies_copy)
|
||||
|
||||
|
||||
self.play(
|
||||
self.row.fade, 0.7,
|
||||
old_row.fade, 0.7,
|
||||
FadeOut(self.tallies),
|
||||
FadeOut(self.tallies_copy),
|
||||
)
|
||||
|
||||
|
||||
# # # # # # # # # # # # # # # # #
|
||||
# SHOW SPLITTING WITH OUTCOMES #
|
||||
# # # # # # # # # # # # # # # # #
|
||||
|
@ -685,13 +713,6 @@ class BrickRowScene(PiCreatureScene):
|
|||
#rate_func = there_and_back_with_pause,
|
||||
run_time = 5))
|
||||
self.wait()
|
||||
self.play(LaggedStart(
|
||||
FadeOut, outcomes,
|
||||
#rate_func = there_and_back_with_pause,
|
||||
run_time = 5))
|
||||
|
||||
self.wait()
|
||||
self.play(FadeIn(self.tallies))
|
||||
|
||||
brace1 = Brace(self.row.rects[2], UP)
|
||||
brace2 = Brace(self.row.rects[3], UP)
|
||||
|
@ -705,6 +726,15 @@ class BrickRowScene(PiCreatureScene):
|
|||
Write(p2),
|
||||
)
|
||||
self.wait()
|
||||
self.play(LaggedStart(
|
||||
FadeOut, outcomes,
|
||||
#rate_func = there_and_back_with_pause,
|
||||
run_time = 5),
|
||||
)
|
||||
self.play(
|
||||
FadeIn(self.tallies)
|
||||
)
|
||||
self.wait()
|
||||
|
||||
self.play(
|
||||
FadeOut(brace1),
|
||||
|
@ -715,7 +745,6 @@ class BrickRowScene(PiCreatureScene):
|
|||
self.wait()
|
||||
|
||||
|
||||
|
||||
# put visuals for other probability distribtuions here
|
||||
|
||||
# back to three coin flips, show all 8 outcomes
|
||||
|
|
|
@ -41,8 +41,9 @@ class GenericMorphBrickRowIntoHistogram(Scene):
|
|||
for rect in self.row.rects:
|
||||
rect.set_stroke(color = WHITE, width = 3)
|
||||
|
||||
self.wait()
|
||||
self.play(self.row.rects.space_out_submobjects, {"factor" : 1.3})
|
||||
|
||||
self.wait()
|
||||
anims = []
|
||||
for brick in self.row.rects:
|
||||
anims.append(brick.rotate)
|
||||
|
@ -52,6 +53,7 @@ class GenericMorphBrickRowIntoHistogram(Scene):
|
|||
anims.append(FadeOut(tallies))
|
||||
self.play(*anims)
|
||||
|
||||
self.wait()
|
||||
|
||||
anims = []
|
||||
for (i,brick) in enumerate(self.row.rects):
|
||||
|
@ -59,6 +61,7 @@ class GenericMorphBrickRowIntoHistogram(Scene):
|
|||
anims.append(self.bar_anchors[i])
|
||||
anims.append({"direction" : UP, "buff" : 0})
|
||||
self.play(*anims)
|
||||
self.wait()
|
||||
|
||||
self.bars.create_outline()
|
||||
anims = [
|
||||
|
@ -68,6 +71,7 @@ class GenericMorphBrickRowIntoHistogram(Scene):
|
|||
anims.append(FadeIn(self.bars.outline))
|
||||
self.play(*anims)
|
||||
|
||||
self.wait()
|
||||
|
||||
|
||||
class MorphBrickRowIntoHistogram3(GenericMorphBrickRowIntoHistogram):
|
||||
|
@ -115,12 +119,14 @@ class MorphBrickRowIntoHistogram3(GenericMorphBrickRowIntoHistogram):
|
|||
if i != 0:
|
||||
y_guide.add(y_guide_label)
|
||||
y_guides.add(y_guide)
|
||||
self.wait()
|
||||
|
||||
self.play(
|
||||
FadeIn(y_guides),
|
||||
Animation(self.bars.outline),
|
||||
Animation(self.bars)
|
||||
)
|
||||
self.wait()
|
||||
|
||||
self.play(
|
||||
FadeIn(x_axis),
|
||||
|
@ -137,10 +143,12 @@ class MorphBrickRowIntoHistogram3(GenericMorphBrickRowIntoHistogram):
|
|||
|
||||
total_area_group = VGroup(total_area_text, area_decimal)
|
||||
total_area_group.move_to(2.7 * UP)
|
||||
self.wait()
|
||||
|
||||
self.play(
|
||||
FadeIn(total_area_text),
|
||||
)
|
||||
self.wait()
|
||||
|
||||
cumulative_areas = [0.125, 0.5, 0.875, 1]
|
||||
covering_rects = self.bars.copy()
|
||||
|
@ -165,6 +173,7 @@ class MorphBrickRowIntoHistogram3(GenericMorphBrickRowIntoHistogram):
|
|||
FadeOut(covering_rects),
|
||||
ShowCreation(total_area_rect)
|
||||
)
|
||||
self.wait()
|
||||
|
||||
|
||||
|
||||
|
@ -194,12 +203,14 @@ class MorphBrickRowIntoHistogram20(GenericMorphBrickRowIntoHistogram):
|
|||
|
||||
nb_tails_label = TextMobject("\# of tails")
|
||||
nb_tails_label.move_to(5 * RIGHT + 2.5 * DOWN)
|
||||
self.wait()
|
||||
|
||||
self.play(
|
||||
FadeIn(x_axis),
|
||||
FadeIn(x_labels),
|
||||
FadeIn(nb_tails_label)
|
||||
)
|
||||
self.wait()
|
||||
|
||||
# draw y-guides
|
||||
|
||||
|
@ -221,6 +232,7 @@ class MorphBrickRowIntoHistogram20(GenericMorphBrickRowIntoHistogram):
|
|||
|
||||
self.bring_to_back(y_guides)
|
||||
self.play(FadeIn(y_guides), Animation(self.bars))
|
||||
self.wait()
|
||||
|
||||
histogram_width = self.bars.get_width()
|
||||
histogram_height = self.bars.get_height()
|
||||
|
@ -247,6 +259,7 @@ class MorphBrickRowIntoHistogram20(GenericMorphBrickRowIntoHistogram):
|
|||
anims.append(ORIGIN)
|
||||
|
||||
self.play(*anims)
|
||||
self.wait()
|
||||
|
||||
anims = []
|
||||
for (guide, i, h) in zip(y_guides, prob_grid, y_guide_heights):
|
||||
|
@ -265,6 +278,7 @@ class MorphBrickRowIntoHistogram20(GenericMorphBrickRowIntoHistogram):
|
|||
anims.append(self.bars.get_bottom())
|
||||
|
||||
self.play(*anims)
|
||||
self.wait()
|
||||
|
||||
class MorphBrickRowIntoHistogram100(MorphBrickRowIntoHistogram20):
|
||||
CONFIG = {
|
||||
|
|
29
active_projects/eop/chapter1/stacking_coins.py
Normal file
29
active_projects/eop/chapter1/stacking_coins.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from big_ol_pile_of_manim_imports import *
|
||||
from active_projects.eop.reusable_imports import *
|
||||
|
||||
|
||||
class StackingCoins(Scene):
|
||||
|
||||
def construct(self):
|
||||
|
||||
h = t = 0
|
||||
heads_stack = HeadsStack(size = h)
|
||||
heads_stack.next_to(0.5*LEFT + 3*DOWN, UP)
|
||||
tails_stack = TailsStack(size = t)
|
||||
tails_stack.next_to(0.5*RIGHT + 3*DOWN, UP)
|
||||
self.add(heads_stack, tails_stack)
|
||||
|
||||
for i in range(120):
|
||||
flip = np.random.choice(["H", "T"])
|
||||
if flip == "H":
|
||||
h += 1
|
||||
new_heads_stack = HeadsStack(size = h)
|
||||
new_heads_stack.next_to(0.5*LEFT + 3*DOWN, UP)
|
||||
self.play(Transform(heads_stack, new_heads_stack,
|
||||
run_time = 0.2))
|
||||
elif flip == "T":
|
||||
t += 1
|
||||
new_tails_stack = TailsStack(size = t)
|
||||
new_tails_stack.next_to(0.5*RIGHT + 3*DOWN, UP)
|
||||
self.play(Transform(tails_stack, new_tails_stack,
|
||||
run_time = 0.2))
|
31
active_projects/eop/chapter1/think_about_coin.py
Normal file
31
active_projects/eop/chapter1/think_about_coin.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
from big_ol_pile_of_manim_imports import *
|
||||
from active_projects.eop.reusable_imports import *
|
||||
|
||||
class RandyThinksAboutCoin(PiCreatureScene):
|
||||
|
||||
def construct(self):
|
||||
|
||||
randy = self.get_primary_pi_creature()
|
||||
randy.center()
|
||||
self.add(randy)
|
||||
self.wait()
|
||||
h_or_t = BinaryOption(UprightHeads().scale(3), UprightTails().scale(3),
|
||||
text_scale = 1.5)
|
||||
self.think(h_or_t, direction = LEFT)
|
||||
|
||||
v = 0.3
|
||||
self.play(
|
||||
h_or_t[0].shift,v*UP,
|
||||
h_or_t[2].shift,v*DOWN,
|
||||
)
|
||||
self.play(
|
||||
h_or_t[0].shift,2*v*DOWN,
|
||||
h_or_t[2].shift,2*v*UP,
|
||||
)
|
||||
self.play(
|
||||
h_or_t[0].shift,v*UP,
|
||||
h_or_t[2].shift,v*DOWN,
|
||||
)
|
||||
|
||||
self.wait()
|
46
active_projects/eop/chapter1/what_does_probability_mean.py
Normal file
46
active_projects/eop/chapter1/what_does_probability_mean.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
|
||||
from big_ol_pile_of_manim_imports import *
|
||||
|
||||
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.play(
|
||||
self.students[1].change_mode, "plain"
|
||||
)
|
||||
self.wait()
|
||||
self.play(RemovePiCreatureBubble(self.students[1]))
|
||||
|
||||
self.wait()
|
||||
|
||||
self.teacher_says("Don't worry -- philosophy can come later!")
|
||||
self.wait()
|
||||
|
||||
|
||||
|
||||
class EmptyTSScene(TeacherStudentsScene):
|
||||
CONFIG = {
|
||||
"default_pi_creature_kwargs": {
|
||||
"color": MAROON_E,
|
||||
"flip_at_start": True,
|
||||
},
|
||||
}
|
||||
|
||||
def construct(self):
|
||||
|
||||
self.wait()
|
||||
self.play(*[
|
||||
ApplyMethod(pi.look_at,ORIGIN) for pi in self.get_pi_creatures()
|
||||
])
|
||||
self.wait(8)
|
|
@ -2,11 +2,14 @@ from mobject.types.vectorized_mobject import *
|
|||
from mobject.svg.tex_mobject import *
|
||||
|
||||
class BinaryOption(VMobject):
|
||||
CONFIG = {
|
||||
"text_scale" : 0.5
|
||||
}
|
||||
|
||||
def __init__(self, mob1, mob2, **kwargs):
|
||||
|
||||
VMobject.__init__(self, **kwargs)
|
||||
text = TextMobject("or").scale(0.5)
|
||||
text = TextMobject("or").scale(self.text_scale)
|
||||
mob1.next_to(text, LEFT)
|
||||
mob2.next_to(text, RIGHT)
|
||||
self.add(mob1, text, mob2)
|
||||
|
|
|
@ -6,8 +6,8 @@ from active_projects.eop.reusables.upright_coins import *
|
|||
class BrickRow(VMobject):
|
||||
|
||||
CONFIG = {
|
||||
"left_color" : RED,
|
||||
"right_color" : BLUE,
|
||||
"left_color" : COLOR_HEADS,
|
||||
"right_color" : COLOR_TAILS,
|
||||
"height" : 1.0,
|
||||
"width" : 8.0,
|
||||
"outcome_shrinkage_factor_x" : 0.95,
|
||||
|
@ -104,14 +104,14 @@ class BrickRow(VMobject):
|
|||
outcome_width = float(self.width) / (2 ** r)
|
||||
outcome_height = self.height
|
||||
|
||||
corner_radius = min(0.1, 0.3 * min(outcome_width, outcome_height))
|
||||
corner_radius = 0.1 # max(0.1, 0.3 * min(outcome_width, outcome_height))
|
||||
# this scales down the corner radius for very narrow rects
|
||||
rect = RoundedRectangle(
|
||||
width = outcome_width,
|
||||
height = outcome_height,
|
||||
corner_radius = corner_radius,
|
||||
fill_color = WHITE,
|
||||
fill_opacity = 0.2,
|
||||
fill_color = OUTCOME_COLOR,
|
||||
fill_opacity = OUTCOME_OPACITY,
|
||||
stroke_width = 0
|
||||
)
|
||||
rects = VGroup()
|
||||
|
|
|
@ -9,10 +9,16 @@ COIN_STROKE_WIDTH = 2
|
|||
|
||||
COIN_SEQUENCE_SPACING = 0.1
|
||||
|
||||
GRADE_COLOR_1 = COLOR_HEADS = RED
|
||||
GRADE_COLOR_2 = COLOR_TAILS = BLUE_E
|
||||
GRADE_COLOR_1 = COLOR_HEADS = RED_E
|
||||
GRADE_COLOR_2 = COLOR_TAILS = BLUE_C
|
||||
|
||||
COLOR_HEADS_COIN = RED
|
||||
COLOR_TAILS_COIN = BLUE_E
|
||||
|
||||
TALLY_BACKGROUND_WIDTH = 1.0
|
||||
TALLY_BACKGROUND_COLOR = BLACK
|
||||
|
||||
SICKLY_GREEN = "#9BBD37"
|
||||
SICKLY_GREEN = "#9BBD37"
|
||||
|
||||
OUTCOME_COLOR = WHITE
|
||||
OUTCOME_OPACITY = 0.5
|
|
@ -24,13 +24,13 @@ class UprightCoin(Circle):
|
|||
|
||||
class UprightHeads(UprightCoin):
|
||||
CONFIG = {
|
||||
"fill_color": COLOR_HEADS,
|
||||
"fill_color": COLOR_HEADS_COIN,
|
||||
"symbol": "H",
|
||||
}
|
||||
|
||||
class UprightTails(UprightCoin):
|
||||
CONFIG = {
|
||||
"fill_color": COLOR_TAILS,
|
||||
"fill_color": COLOR_TAILS_COIN,
|
||||
"symbol": "T",
|
||||
}
|
||||
|
||||
|
@ -120,13 +120,13 @@ class FlatCoin(UprightCoin):
|
|||
|
||||
class FlatHeads(FlatCoin):
|
||||
CONFIG = {
|
||||
"fill_color": COLOR_HEADS,
|
||||
"fill_color": COLOR_HEADS_COIN,
|
||||
"symbol": "H",
|
||||
}
|
||||
|
||||
class FlatTails(FlatCoin):
|
||||
CONFIG = {
|
||||
"fill_color": COLOR_TAILS,
|
||||
"fill_color": COLOR_TAILS_COIN,
|
||||
"symbol": "T",
|
||||
}
|
||||
|
|
@ -16,6 +16,15 @@ class WhatDoesItReallyMean(TeacherStudentsScene):
|
|||
student_q.set_color_by_tex("probability", YELLOW)
|
||||
self.student_says(student_q, target_mode = "sassy")
|
||||
self.wait()
|
||||
|
||||
question_bubble = VGroup(student_q, students[1].bubble)
|
||||
scaled_qb = question_bubble.copy()
|
||||
scaled_qb.scale(0.4).to_corner(UL)
|
||||
self.play(Transform(question_bubble, scaled_qb))
|
||||
self.wait()
|
||||
|
||||
|
||||
|
||||
self.teacher_says("Don't worry -- philosophy can come later!")
|
||||
self.wait()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue