trying (and failing) to get the pi creature to flash through the class

This commit is contained in:
Ben Hambrecht 2018-05-08 13:23:24 +02:00
parent 08b0cc0dea
commit 69d899a6fe
6 changed files with 140 additions and 46 deletions

View file

@ -677,11 +677,18 @@ class BrickRowScene(PiCreatureScene):
with_labels = True,
inset = True)
self.play(FadeOut(self.tallies))
self.play(LaggedStart(
FadeIn, outcomes))
self.wait()
self.play(LaggedStart(
FadeOut, outcomes))
FadeIn, outcomes,
#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)
@ -705,6 +712,33 @@ class BrickRowScene(PiCreatureScene):
)
self.wait()
# put visuals for other probability distribtuions here
# back to three coin flips, show all 8 outcomes
self.play(
LaggedStart(FadeIn, outcomes,
#rate_func = there_and_back_with_pause,
run_time = 5),
FadeOut(self.tallies)
)
self.wait()
self.play(
LaggedStart(FadeOut, outcomes,
#rate_func = there_and_back_with_pause,
run_time = 5),
FadeIn(self.tallies)
)
return
# # # # # # # #
# FOURTH FLIP #
# # # # # # # #
@ -889,3 +923,12 @@ class BrickRowScene(PiCreatureScene):
#self.merge_decimals()
self.wait()

View file

@ -14,15 +14,25 @@ class ProbabilityDistributions(PiCreatureScene):
def construct(self):
lag_ratio = 0.2
run_time = 5
run_time = 3
text = TextMobject("Probability distributions", color = YELLOW)
text.to_edge(UP)
text_rect = SurroundingRectangle(text, buff = MED_SMALL_BUFF)
self.play(
FadeIn(text),
ShowCreation(text_rect)
)
# WEATHER FORECAST
unit_rect = Rectangle(
height = 4, width = 4
)
height = 3, width = 3
).shift(DOWN)
p_rain = 0.23
p_sun = 1 - p_rain
@ -38,7 +48,7 @@ class ProbabilityDistributions(PiCreatureScene):
sun_rect.set_fill(color = YELLOW, opacity = opacity)
sun_rect.set_stroke(width = 0)
self.add(unit_rect, rain_rect, sun_rect)
self.play(FadeIn(VGroup(unit_rect, rain_rect, sun_rect)))
rain = SVGMobject(file_name = "rain").scale(0.35)
sun = SVGMobject(file_name = "sun").scale(0.35)
@ -189,7 +199,8 @@ 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 = LARGE_BUFF)
coin_flip_rect.target.to_corner(UR, buff = MED_LARGE_BUFF)
coin_flip_rect.target.shift(DOWN)
self.play(
MoveToTarget(coin_flip_rect)
@ -255,25 +266,3 @@ class ProbabilityDistributions(PiCreatureScene):
rate_func=there_and_back_with_pause,
run_time=run_time
)

View file

@ -1,12 +1,13 @@
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 *
class QuizResult(Scene):
class QuizResult(PiCreatureScene):
CONFIG = {
"pi_creatures_start_on_screen" : False
}
def construct(self):
@ -23,14 +24,15 @@ class QuizResult(Scene):
return quiz
highlight_color = YELLOW
highlight_color = WHITE
nb_students_x = 5
nb_students_y = 3
spacing_students_x = 2.0
spacing_students_y = 2.2
all_students = VGroup()
all_students = PiCreatureClass(
width = nb_students_x, height = nb_students_y)# VGroup()
student_points = []
grades = []
grades_count = []
@ -39,9 +41,10 @@ class QuizResult(Scene):
for j in range(nb_students_y):
x = i * spacing_students_x
y = j * spacing_students_y
pi = PiCreature().scale(0.3)
pi.move_to([x,y,0])
all_students.add(pi)
#pi = PiCreature().scale(0.3)
#pi.move_to([x,y,0])
#all_students.add(pi)
all_students[i*nb_students_y + j].move_to([x,y,0])
q1 = np.random.choice([True, False])
q2 = np.random.choice([True, False])
q3 = np.random.choice([True, False])
@ -55,7 +58,8 @@ class QuizResult(Scene):
all_students.move_to(ORIGIN)
self.add(all_students)
self.pi_creatures = all_students
self.play(FadeIn(all_students))
all_quizzes = VGroup()
@ -133,17 +137,20 @@ class QuizResult(Scene):
)
grade_hist.move_to(all_students)
self.play(FadeIn(grade_hist))
self.play(
FadeIn(grade_hist),
FadeOut(all_students)
)
nb_students_label = TextMobject("\# of students", color = highlight_color)
nb_students_label.move_to(3 * LEFT + 2 * UP)
nb_students_label.move_to(5 * LEFT + 2 * UP)
arrows = VGroup(*[
Arrow(nb_students_label, grade_hist.bars[i].get_center(),
Arrow(nb_students_label.get_right(), grade_hist.bars[i].get_center(),
color = highlight_color)
for i in range(4)
])
self.play(Write(nb_students_label), LaggedStart(ShowCreation,arrows))
self.play(Write(nb_students_label), LaggedStart(GrowArrow,arrows))
percentage_label = TextMobject("\% of students", color = highlight_color)
percentage_label.move_to(nb_students_label)
@ -155,6 +162,7 @@ class QuizResult(Scene):
unit = "\%",
color = highlight_color
)
new_label.scale(0.7)
new_label.move_to(label)
anims.append(Transform(label, new_label))
anims.append(ReplacementTransform(nb_students_label, percentage_label))
@ -190,6 +198,12 @@ class QuizResult(Scene):
grade_hist,
direction = "vertical",
mode = "random",
cell_opacity = 0.5,
run_time = 1
),
FlashThroughClass(
all_students,
mode = "random",
run_time = 5
)
)

View file

@ -277,6 +277,15 @@ class FlashThroughHistogram(Animation):
self.mobject.remove(self.prototype_cell)
def clean_up(self):
self.update(1)
self.remove(prototype_cell)
if surrounding_scene is not None:
if self.is_remover():
surrounding_scene.remove(self.mobject)
else:
surrounding_scene.add(self.mobject)
return self

View file

@ -0,0 +1,39 @@
from for_3b1b_videos.pi_creature import *
class PiCreatureClass(VGroup):
CONFIG = {
"width" : 3,
"height" : 2
}
def __init__(self, **kwargs):
VGroup.__init__(self, **kwargs)
for i in range(self.width):
for j in range(self.height):
pi = PiCreature().scale(0.3)
pi.move_to(i*DOWN + j* RIGHT)
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)

View file

@ -742,8 +742,8 @@ class Mobject(Container):
def submobject_family(self):
sub_families = map(Mobject.submobject_family, self.submobjects)
# all_mobjects = [self] + list(it.chain(*sub_families))
all_mobjects = list(it.chain(*sub_families)) + [self]
all_mobjects = [self] + list(it.chain(*sub_families))
#all_mobjects = list(it.chain(*sub_families)) + [self]
return remove_list_redundancies(all_mobjects)
def family_members_with_points(self):