def get_plus_one_anim(self, count): plus_one = TexMobject("+1") plus_one.highlight(YELLOW) plus_one.move_to(count) plus_one.next_to(count, DOWN) plus_one.generate_target() plus_one.target.move_to(count) plus_one.target.set_fill(opacity = 0) move = MoveToTarget(plus_one, remover = True) grow = GrowFromCenter(plus_one) return UpdateFromAlphaFunc( plus_one, lambda m, a : ( (grow if a < 0.5 else move).update(2*a%1) ), remover = True, rate_func = double_smooth, run_time = 2 )
def construct(self): title = TextMobject("Putnam Competition") title.to_edge(UP, buff = MED_SMALL_BUFF) title.highlight(BLUE) six_hours = TextMobject("6", "hours") three_hours = TextMobject("3", "hours") for mob in six_hours, three_hours: mob.next_to(title, DOWN, MED_LARGE_BUFF) # mob.highlight(BLUE) three_hours.shift(SPACE_WIDTH*LEFT/2) three_hours_copy = three_hours.copy() three_hours_copy.shift(SPACE_WIDTH*RIGHT) question_groups = VGroup(*[ VGroup(*[ TextMobject("%s%d)"%(c, i)) for i in range(1, 7) ]).arrange_submobjects(DOWN, buff = MED_LARGE_BUFF) for c in "A", "B" ]).arrange_submobjects(RIGHT, buff = SPACE_WIDTH - MED_SMALL_BUFF) question_groups.to_edge(LEFT) question_groups.to_edge(DOWN, MED_LARGE_BUFF) flat_questions = VGroup(*it.chain(*question_groups)) rects = VGroup() for questions in question_groups: rect = SurroundingRectangle(questions, buff = MED_SMALL_BUFF) rect.set_stroke(WHITE, 2) rect.stretch_to_fit_width(SPACE_WIDTH - 1) rect.move_to(questions.get_left() + MED_SMALL_BUFF*LEFT, LEFT) rects.add(rect) out_of_tens = VGroup() for question in flat_questions: out_of_ten = TexMobject("/10") out_of_ten.highlight(GREEN) out_of_ten.move_to(question) dist = rects[0].get_width() - 1.2 out_of_ten.shift(dist*RIGHT) out_of_tens.add(out_of_ten) out_of_120 = TexMobject("/120") out_of_120.next_to(title, RIGHT, LARGE_BUFF) out_of_120.highlight(GREEN) out_of_120.generate_target() out_of_120.target.to_edge(RIGHT, LARGE_BUFF) median = TexMobject("2") median.next_to(out_of_120.target, LEFT, SMALL_BUFF) median.highlight(RED) median.align_to(out_of_120[-1]) median_words = TextMobject("Typical median $\\rightarrow$") median_words.next_to(median, LEFT) difficulty_strings = [ "Pretty hard", "Hard", "Harder", "Very hard", "Ughhh", "Can I go home?" ] colors = color_gradient([YELLOW, RED], len(difficulty_strings)) difficulties = VGroup() for i, s, color in zip(it.count(), difficulty_strings, colors): for question_group in question_groups: question = question_group[i] text = TextMobject("\\dots %s \\dots"%s) text.scale(0.7) text.next_to(question, RIGHT) text.highlight(color) difficulties.add(text) if self.dont_animate: test = VGroup() test.rect = rects[0] test.questions = question_groups[0] test.out_of_tens = VGroup(*out_of_tens[:6]) test.difficulties = VGroup(*difficulties[::2]) test.digest_mobject_attrs() self.test = test return self.add(title) self.play(Write(six_hours)) self.play(LaggedStart( GrowFromCenter, flat_questions, run_time = 3, )) self.play( ReplacementTransform(six_hours, three_hours), ReplacementTransform(six_hours.copy(), three_hours_copy), *map(ShowCreation, rects) ) self.dither() self.play(LaggedStart( DrawBorderThenFill, out_of_tens, run_time = 3, stroke_color = YELLOW )) self.dither() self.play(ReplacementTransform( out_of_tens.copy(), VGroup(out_of_120), submobject_mode = "lagged_start", run_time = 2, )) self.dither() self.play( title.next_to, median_words.copy(), LEFT, LARGE_BUFF, MoveToTarget(out_of_120), Write(median_words) ) self.play(Write(median)) self.play(Write(difficulties, run_time = 3)) self.dither()
def construct(self): triples = [(u**2 - v**2, 2 * u * v, u**2 + v**2) for u in range(1, 15) for v in range(1, u) if fractions.gcd(u, v) == 1 and not (u % 2 == v % 2)][:40] triangles = VGroup() titles = VGroup() for i, (a, b, c) in enumerate(triples): triangle = Polygon(ORIGIN, a * RIGHT, a * RIGHT + b * UP) triangle.highlight(WHITE) max_width = max_height = 4 triangle.scale_to_fit_height(max_height) if triangle.get_width() > max_width: triangle.scale_to_fit_width(max_width) triangle.move_to(2 * RIGHT) num_strings = map(str, (a, b, c)) labels = map(TexMobject, num_strings) for label, color in zip(labels, SIDE_COLORS): label.highlight(color) labels[0].next_to(triangle, DOWN) labels[1].next_to(triangle, RIGHT) labels[2].next_to(triangle.get_center(), UP + LEFT) triangle.add(*labels) title = TexMobject(str(a), "^2", "+", str(b), "^2", "=", str(c), "^2") for num, color in zip([a, b, c], SIDE_COLORS): title.highlight_by_tex(str(num), color) title.next_to(triangle, UP, LARGE_BUFF) title.generate_target() title.target.scale(0.5) title.target.move_to( (-SPACE_WIDTH + MED_LARGE_BUFF + 2.7*(i//8))*RIGHT + \ (SPACE_HEIGHT - MED_LARGE_BUFF - (i%8))*UP, UP+LEFT ) triangles.add(triangle) titles.add(title) triangle = triangles[0] title = titles[0] self.play( Write(triangle), Write(title), run_time=2, ) self.dither() self.play(MoveToTarget(title)) for i in range(1, 17): new_triangle = triangles[i] new_title = titles[i] if i < 4: self.play(Transform(triangle, new_triangle), FadeIn(new_title)) self.dither() self.play(MoveToTarget(new_title)) else: self.play(Transform(triangle, new_triangle), FadeIn(new_title.target)) self.dither() self.play(FadeOut(triangle)) self.play( LaggedStart(FadeIn, VGroup(*[title.target for title in titles[17:]]), run_time=5)) self.dither(2)