def construct(self): analysis = get_image("Analysis_page_showing_pi") analysis.scale_to_fit_height(2 * SPACE_HEIGHT) analysis.to_edge(LEFT, buff=0) text = TextMobject("``\\dots set the radius of", "the circle\\dots to be = 1, \\dots \\\\", "through approximations the", "semicircumference \\\\", "of said circle", "has been found to be", "$= 3.14159\\dots$,\\\\", "for which number, for the sake of", "brevity, \\\\ I will write", "$\pi$\\dots''", alignment='') pi_formula = TexMobject("\\pi", "=", "{ \\text{semicircumference}", "\\over", "\\text{radius}}") text.scale_to_fit_width(SPACE_WIDTH) text.next_to(analysis, RIGHT, LARGE_BUFF) text.to_edge(UP) HIGHLIGHT_COLOR = GREEN for mob in text, pi_formula: mob.highlight_by_tex_to_color_map({ "semicircumference": HIGHLIGHT_COLOR, "3.14": HIGHLIGHT_COLOR, "\pi": HIGHLIGHT_COLOR }) terms, generate_anims1, generate_anims2 = get_circle_drawing_terms( radius=1, positioning_func=lambda circ: circ.next_to(text, DOWN, LARGE_BUFF)) terms[0].highlight(HIGHLIGHT_COLOR) terms[-1].highlight(HIGHLIGHT_COLOR) pi_formula.next_to(terms, DOWN, buff=0) pi_formula.align_to(text, alignment_vect=RIGHT) pi_formula[0].scale(2, about_edge=RIGHT) self.add(analysis) self.play(*generate_anims2(), rate_func=lambda t: 0.5 * smooth(t)) self.play(LaggedStart(FadeIn, text), run_time=5) self.play(FadeIn(pi_formula)) self.wait()
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()
class DecimalNumber(VMobject): CONFIG = { "num_decimal_points": 2, "digit_to_digit_buff": 0.05, "show_ellipsis": False, "unit": None, #Aligned to bottom unless it starts with "^" "include_background_rectangle": False, } def __init__(self, number, **kwargs): VMobject.__init__(self, **kwargs) self.number = number ndp = self.num_decimal_points #Build number string if isinstance(number, complex): num_string = '%.*f%s%.*fi' % (ndp, number.real, "-" if number.imag < 0 else "+", ndp, abs(number.imag)) else: num_string = '%.*f' % (ndp, number) negative_zero_string = "-%.*f" % (ndp, 0.) if num_string == negative_zero_string: num_string = num_string[1:] self.add(*[TexMobject(char, **kwargs) for char in num_string]) #Add non-numerical bits if self.show_ellipsis: self.add(TexMobject("\\dots")) if num_string.startswith("-"): minus = self.submobjects[0] minus.next_to(self.submobjects[1], LEFT, buff=self.digit_to_digit_buff) if self.unit != None: self.unit_sign = TexMobject(self.unit) self.add(self.unit_sign) self.arrange_submobjects(buff=self.digit_to_digit_buff, aligned_edge=DOWN) #Handle alignment of parts that should be aligned #to the bottom for i, c in enumerate(num_string): if c == "-" and len(num_string) > i + 1: self[i].align_to(self[i + 1], alignment_vect=UP) if self.unit and self.unit.startswith("^"): self.unit_sign.align_to(self, UP) # if self.include_background_rectangle: self.add_background_rectangle() def add_background_rectangle(self): #TODO, is this the best way to handle #background rectangles? self.background_rectangle = BackgroundRectangle(self) self.submobjects = [ self.background_rectangle, VGroup(*self.submobjects) ] return self