def construct(self): eq1a = TextMobject("4x + 3y") eq1b = TextMobject("=") eq1c = TextMobject("0") eq2a = TextMobject("5x - 2y") eq2b = TextMobject("=") eq2c = TextMobject("3") eq1b.next_to(eq1a, RIGHT) eq1c.next_to(eq1b, RIGHT) eq2a.shift(DOWN) eq2b.shift(DOWN) eq2c.shift(DOWN) eq2a.align_to(eq1a, LEFT) eq2b.align_to(eq1b, LEFT) eq2c.align_to(eq1c, LEFT) eq_group = VGroup(eq1a, eq2a) braces = Brace(eq_group, LEFT) eq_text = braces.get_text("A pair of equations") self.add(eq1a, eq1b, eq1c) self.add(eq2a, eq2b, eq2c) self.play(GrowFromCenter(braces), Write(eq_text)) self.wait(3)
def initialize_texts(self): geom_text = TextMobject("一个边长为$n$的正六边形", "和一些边长为1的菱形") eqtri_text = TextMobject("它们都是由若干正三角形组成的") three_types_text = TextMobject("因为朝向不同,菱形被分成三种") try_tiling_text = TextMobject("现在用这些菱形", "镶嵌", "正六边形...") remark = TextMobject("(无间隙且不重叠地覆盖)") claim_text = TextMobject("最终的图案中", "每种菱形的数量一定都是$n^2$") twist_text = TextMobject("改变菱形的摆放方式", "或者改变正六边形的大小", "这个结论依然成立") how_to_prove_text = TextMobject("如何证明?", "") for text in (geom_text, claim_text, twist_text): text.arrange_submobjects(DOWN, aligned_edge=LEFT) try_tiling_text[1].set_color(GREEN) remark.scale(0.5) remark.set_color(GREEN) remark.next_to(try_tiling_text[1], DOWN, buff=0.1) how_to_prove_text.set_color(YELLOW) bg_texts = VGroup( geom_text, eqtri_text, three_types_text, VGroup(try_tiling_text, remark), ) q_texts = VGroup( claim_text, twist_text, ) for texts in (bg_texts, q_texts, how_to_prove_text): texts.arrange_submobjects(DOWN, aligned_edge=LEFT, buff=1) texts.to_corner(LEFT + UP) self.bg_texts = bg_texts self.q_texts = q_texts self.how_to_prove_text = how_to_prove_text
def construct(self): quote = TextMobject("Imagination is more important than knowledge") quote.set_color(RED) quote.to_edge(UP) quote2 = TextMobject( "A person who never made a mistake never tried anything new") quote2.set_color(YELLOW) author = TextMobject("- Albert Einstein") author.scale(0.75) corner = quote.get_corner(DOWN + RIGHT) print("corner", corner) author.next_to(corner, ORIGIN) self.add(quote, author) self.wait(2) self.play( Transform(quote, quote2), ApplyMethod(author.move_to, quote2.get_corner(DOWN + RIGHT) + DOWN + 2 * LEFT)) self.play(ApplyMethod(author.scale, 1.5)) author.match_color(quote2) self.play(FadeOut(quote), FadeOut(author)) self.wait()
def add_title(self, title="Sample space", buff=MED_SMALL_BUFF): # TODO, should this really exist in SampleSpaceScene title_mob = TextMobject(title) if title_mob.get_width() > self.get_width(): title_mob.set_width(self.get_width()) title_mob.next_to(self, UP, buff=buff) self.title = title_mob self.add(title_mob)
def add_title(self, title="Sample space", buff=MED_SMALL_BUFF): # TODO, should this really exist in SampleSpaceScene title_mob = TextMobject(title) if title_mob.get_width() > self.get_width(): title_mob.set_width(self.get_width()) title_mob.next_to(self, UP, buff=buff) self.title = title_mob self.add(title_mob)
def setup(self): MovingCameraScene.setup(self) frame = self.camera_frame frame.shift(DOWN) self.logo = Logo() name = TextMobject("3Blue1Brown") name.scale(2.5) name.next_to(self.logo, DOWN, buff=MED_LARGE_BUFF) name.set_sheen(-0.2, DR) self.channel_name = name
def setup(self): MovingCameraScene.setup(self) frame = self.camera_frame frame.shift(DOWN) self.logo = Logo() name = TextMobject("3Blue1Brown") name.scale(2.5) name.next_to(self.logo, DOWN, buff=MED_LARGE_BUFF) name.set_sheen(-0.2, DR) self.channel_name = name
def setup(self): super().setup() frame = self.camera.frame frame.shift(DOWN) self.logo = Logo() name = TextMobject("3Blue1Brown") name.scale(2.5) name.next_to(self.logo, DOWN, buff=MED_LARGE_BUFF) name.set_gloss(0.2) self.channel_name = name
def add_labels(self): numeral_labels = VGroup(*[ TextMobject(str(i+1)).next_to(self.get_square("a"+str(i+1)), LEFT) for i in range(8) ]) alphabetical_labels = TextMobject(*[chr(97+i) for i in range(8)]) alphabetical_labels.next_to(self.border, DOWN, buff = 0.15) for i, label in enumerate(alphabetical_labels): label.next_to(self.get_square(chr(97+i)+"1"), DOWN, coor_mask = [1, 0, 0]) self.add(numeral_labels, alphabetical_labels) self.numeral_labels = numeral_labels self.alphabetical_labels = alphabetical_labels
def construct(self): my_first_text = TextMobject("Writing with manim is fun") second_line = TextMobject("and easy to do!") second_line.next_to(my_first_text, DOWN) third_line = TextMobject("for me and you!") third_line.next_to(my_first_text, DOWN) self.add(my_first_text, second_line) self.wait(2) self.play(Transform(second_line, third_line)) self.wait(2) second_line.shift(3 * DOWN) self.play(ApplyMethod(my_first_text.shift, 3 * UP)) self.wait()
def _main_title(self): paper_name_a = TextMobject( "Simulating human interactions in supermarkets to") paper_name_b = TextMobject( "measure the risk of COVID-19 contagion at scale") author_list_a = TextMobject( "Serge Plata\\quad Sumanas Sarma\\quad Melvin Lancelot") author_list_b = TextMobject( "Kristine Bagrova\\quad David Romano-Critchley") arxiv = TextMobject("arXiv:2006.15213") paper_name_a.shift(UP) paper_name_b.next_to(paper_name_a, DOWN) author_list_a.scale(0.8) author_list_b.scale(0.8) author_list_a.next_to(paper_name_b, DOWN + DOWN) author_list_b.next_to(author_list_a, DOWN) arxiv.scale(0.6) arxiv.next_to(author_list_b, DOWN + DOWN) self.play(FadeIn(paper_name_a), FadeIn(paper_name_b)) self.wait() self.play(FadeIn(author_list_a), FadeIn(author_list_b)) self.play(FadeIn(arxiv)) self.wait(4) self.play(FadeOut(paper_name_a), FadeOut(paper_name_b), FadeOut(author_list_a), FadeOut(author_list_b), ApplyMethod(arxiv.move_to, BOTTOM + (UP * 0.5)))
def construct(self): my_first_text = TextMobject("Writing with manim is fun") second_line = TextMobject("and easy to do!") second_line.next_to(my_first_text, DOWN) third_line = TextMobject("for me and you!") third_line.next_to(my_first_text, DOWN) self.play(FadeIn(my_first_text), FadeIn(second_line)) self.wait(2) self.play(Transform(second_line, third_line)) self.wait(2) self.play(ApplyMethod(my_first_text.shift, 3 * UP)) self.play(Rotating(second_line), radians=PI, run_time=2) self.wait()
def generate_points(self): image = ImageMobject(self.image_filename) remark = TextMobject(self.remark_text) if self.image_width is not None: image.set_width(self.image_width) if self.text_width is not None: remark.set_width(self.text_width) remark.next_to( image, self.text_position, aligned_edge = self.text_aligned_edge, buff = self.text_buff ) self.add(image) self.add(remark) self.center() self.image = image self.remark = remark
def get_corner_numbers(self, value, symbol): value_mob = TextMobject(value) width = self.get_width() / self.card_width_to_corner_num_width height = self.get_height() / self.card_height_to_corner_num_height value_mob.set_width(width) value_mob.stretch_to_fit_height(height) value_mob.next_to(self.get_corner(UP + LEFT), DOWN + RIGHT, buff=MED_LARGE_BUFF * width) value_mob.set_color(symbol.get_color()) corner_symbol = symbol.copy() corner_symbol.set_width(width) corner_symbol.next_to(value_mob, DOWN, buff=MED_SMALL_BUFF * width) corner_group = VGroup(value_mob, corner_symbol) opposite_corner_group = corner_group.copy() opposite_corner_group.rotate(np.pi, about_point=self.get_center()) return VGroup(corner_group, opposite_corner_group)
def get_det_text(matrix, determinant=None, background_rect=False, initial_scale_factor=2): parens = TexMobject("(", ")") parens.scale(initial_scale_factor) parens.stretch_to_fit_height(matrix.get_height()) l_paren, r_paren = parens.split() l_paren.next_to(matrix, LEFT, buff=0.1) r_paren.next_to(matrix, RIGHT, buff=0.1) det = TextMobject("det") det.scale(initial_scale_factor) det.next_to(l_paren, LEFT, buff=0.1) if background_rect: det.add_background_rectangle() det_text = VGroup(det, l_paren, r_paren) if determinant is not None: eq = TexMobject("=") eq.next_to(r_paren, RIGHT, buff=0.1) result = TexMobject(str(determinant)) result.next_to(eq, RIGHT, buff=0.2) det_text.add(eq, result) return det_text
def get_det_text(matrix, determinant=None, background_rect=False, initial_scale_factor=2): parens = TexMobject("(", ")") parens.scale(initial_scale_factor) parens.stretch_to_fit_height(matrix.get_height()) l_paren, r_paren = parens.split() l_paren.next_to(matrix, LEFT, buff=0.1) r_paren.next_to(matrix, RIGHT, buff=0.1) det = TextMobject("det") det.scale(initial_scale_factor) det.next_to(l_paren, LEFT, buff=0.1) if background_rect: det.add_background_rectangle() det_text = VGroup(det, l_paren, r_paren) if determinant is not None: eq = TexMobject("=") eq.next_to(r_paren, RIGHT, buff=0.1) result = TexMobject(str(determinant)) result.next_to(eq, RIGHT, buff=0.2) det_text.add(eq, result) return det_text
def get_corner_numbers(self, value, symbol): value_mob = TextMobject(value) width = self.get_width() / self.card_width_to_corner_num_width height = self.get_height() / self.card_height_to_corner_num_height value_mob.set_width(width) value_mob.stretch_to_fit_height(height) value_mob.next_to( self.get_corner(UP + LEFT), DOWN + RIGHT, buff=MED_LARGE_BUFF * width ) value_mob.set_color(symbol.get_color()) corner_symbol = symbol.copy() corner_symbol.set_width(width) corner_symbol.next_to( value_mob, DOWN, buff=MED_SMALL_BUFF * width ) corner_group = VGroup(value_mob, corner_symbol) opposite_corner_group = corner_group.copy() opposite_corner_group.rotate( np.pi, about_point=self.get_center() ) return VGroup(corner_group, opposite_corner_group)
def setup_axes(self, animate=False): """ This method sets up the axes of the graph. Parameters ---------- animate (bool=False) Whether or not to animate the setting up of the Axes. """ # TODO, once eoc is done, refactor this to be less redundant. x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width / x_num_range if self.x_labeled_nums is None: self.x_labeled_nums = [] if self.x_leftmost_tick is None: self.x_leftmost_tick = self.x_min x_axis = NumberLine( x_min=self.x_min, x_max=self.x_max, unit_size=self.space_unit_to_x, tick_frequency=self.x_tick_frequency, leftmost_tick=self.x_leftmost_tick, numbers_with_elongated_ticks=self.x_labeled_nums, color=self.axes_color, # Added this line decimal_number_config={"color": self.label_nums_color}) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if len(self.x_labeled_nums) > 0: if self.exclude_zero_label: self.x_labeled_nums = [ x for x in self.x_labeled_nums if x != 0 ] x_axis.add_numbers(*self.x_labeled_nums) if self.x_axis_label: x_label = TextMobject(self.x_axis_label) # Added this line x_label.set_color(self.label_color) x_label.next_to(x_axis.get_tick_marks(), UP + RIGHT, buff=SMALL_BUFF) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height / y_num_range if self.y_labeled_nums is None: self.y_labeled_nums = [] if self.y_bottom_tick is None: self.y_bottom_tick = self.y_min y_axis = NumberLine( x_min=self.y_min, x_max=self.y_max, unit_size=self.space_unit_to_y, tick_frequency=self.y_tick_frequency, leftmost_tick=self.y_bottom_tick, numbers_with_elongated_ticks=self.y_labeled_nums, color=self.axes_color, line_to_number_vect=LEFT, label_direction=LEFT, # yongze added this line decimal_number_config={"color": self.label_nums_color}, ) y_axis.shift(self.graph_origin - y_axis.number_to_point(0)) y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0)) if len(self.y_labeled_nums) > 0: if self.exclude_zero_label: self.y_labeled_nums = [ y for y in self.y_labeled_nums if y != 0 ] y_axis.add_numbers(*self.y_labeled_nums) if self.y_axis_label: y_label = TextMobject(self.y_axis_label) # yongze Added this line y_label.set_color(self.label_color) y_label.next_to(y_axis.get_corner(UP + RIGHT), UP + RIGHT, buff=SMALL_BUFF) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label if animate: self.play(Write(VGroup(x_axis, y_axis))) else: self.add(x_axis, y_axis) self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis) self.default_graph_colors = it.cycle(self.default_graph_colors)
def get_author(self, quote): author = TextMobject(self.text_size + " --" + self.author) author.next_to(quote, DOWN, buff=self.author_buff) author.set_color(YELLOW) return author
def get_author(self, quote): author = TextMobject(self.text_size + " --" + self.author) author.next_to(quote, DOWN, buff=self.author_buff) author.set_color(YELLOW) return author
def construct(self): self._main_title() text_one = TextMobject("Given a list of items sold") text_two: TextMobject = TextMobject( "Randomly choose items matching this distribution") text_two.next_to(text_one, DOWN) number_line = NumberLine( numbers_with_elongated_ticks=[0, 1], include_numbers=True, x_min=0, x_max=1, unit_size=10, tick_frequency=0.1, # decimal_number_config={"num_decimal_places": 1}, numbers_to_show=[0, 1]) number_line.next_to(text_two, UP) self.play(ShowCreation(text_one)) self.wait() self.play(ShowCreation(text_two)) self.wait(4) apples_text = TextMobject("Apples:") apples_text.set_color(self._apple_colour) apples_text.to_edge(UP) apples_text.align_to(text_two, LEFT) apple_count_text = TextMobject(f"{self._apple_count}") apple_count_text.set_color(self._apple_colour) apple_count_text.next_to(apples_text, RIGHT) banana_text = TextMobject("Bananas:") banana_text.set_color(self._banana_colour) banana_text.next_to(apples_text, DOWN) banana_text.align_to(apples_text, LEFT) banana_count_text = TextMobject(f"{self._banana_count}") banana_count_text.set_color(self._banana_colour) banana_count_text.next_to(banana_text, RIGHT) self.play(Transform(text_one, apples_text)) self.play(ShowCreation(apple_count_text)) self.play(ShowCreation(banana_text), ShowCreation(banana_count_text)) banana_bar = Rectangle( height=0.4, width=number_line.point_to_number(self._banana_fraction * 10) * (number_line.number_to_point(1)[0]), color=self._banana_colour, fill_color=self._banana_colour, fill_opacity=0.75) banana_bar.next_to(banana_count_text, RIGHT + RIGHT) apple_bar = Rectangle( height=0.4, width=number_line.point_to_number(self._apple_fraction * 10) * (number_line.number_to_point(1)[0]), color=self._apple_colour, fill_color=self._apple_colour, fill_opacity=0.75) apple_bar.next_to(banana_bar, UP) apple_bar.align_to(banana_bar, LEFT) self.play(FadeIn(apple_bar), FadeIn(banana_bar)) self.wait(1.5) apple_fraction_text = TextMobject("$\\frac{" + str(self._apple_count) + "}{" + str(self._apple_count + self._banana_count) + "} = " + str(self._apple_fraction) + "$") apple_fraction_text.next_to(apple_bar, RIGHT) banana_fraction_text = TextMobject("$\\frac{" + str(self._banana_count) + "}{" + str(self._apple_count + self._banana_count) + "} = " + str(self._banana_fraction) + "$") banana_fraction_text.next_to(banana_bar, RIGHT) self.play(ShowCreation(apple_fraction_text)) self.play(ShowCreation(banana_fraction_text)) self.wait(2) number_line_map_text = TextMobject( "Map these counts to values between 0 and 1") number_line_map_text.next_to(text_two, UP) self.play(ShowCreation(number_line_map_text)) self.wait(3) self.play(Transform(number_line_map_text, number_line)) apple_num_ln_bar = Rectangle( height=0.4, # width=1 - self._apple_fraction * (number_line.number_to_point(1)[0]), width=number_line.point_to_number(self._apple_fraction * 10) * (number_line.number_to_point(1)[0]), color=self._apple_colour, fill_color=self._apple_colour, fill_opacity=0.25) apple_num_ln_bar.move_to(apple_bar, LEFT) self.add(apple_num_ln_bar) self.wait(2) self.play( ApplyMethod(apple_num_ln_bar.move_to, number_line.number_to_point(0), LEFT)) banana_num_ln_bar = Rectangle( height=0.4, width=number_line.point_to_number(self._banana_fraction * 10) * (number_line.number_to_point(1)[0]), color=self._banana_colour, fill_color=self._banana_colour, fill_opacity=0.25) banana_num_ln_bar.move_to(banana_bar, LEFT) self.add(banana_num_ln_bar) self.wait(2) self.play( ApplyMethod(banana_num_ln_bar.move_to, number_line.number_to_point(1), RIGHT)) text_scale: float = 0.75 get_rnd_full = TextMobject( "Get a random number $n$ between 0 and 1 (uniform distribution)") get_apple_text = TextMobject( f"Apple\\quad if $n <= {self._apple_fraction}$", tex_to_color_map={"Apple": self._apple_colour}) get_banana_text = TextMobject( f"Banana\\quad if $n > {self._apple_fraction}$", tex_to_color_map={"Banana": self._banana_colour}) get_rnd_full.scale(text_scale) get_rnd_full.next_to(text_two, DOWN) get_banana_text.next_to(get_apple_text, DOWN) step_group = VGroup(get_apple_text, get_banana_text) brace = Brace(step_group, LEFT) step_text_d = brace.get_text("$n \\sim U(0, 1)$") step_text_d.scale(text_scale) step_text_d.next_to(get_rnd_full, DOWN + DOWN) step_text_d.shift(LEFT) brace.next_to(step_text_d, RIGHT) step_group.scale(text_scale) step_group.next_to(step_text_d, RIGHT + RIGHT + RIGHT) self.wait(2) self.play(ShowCreation(get_rnd_full)) self.wait(2) self.play(ShowCreation(step_text_d)) self.wait(2) self.play(GrowFromCenter(brace)) self.wait() self.play(ShowCreation(get_apple_text)) self.wait(2) self.play(ShowCreation(get_banana_text)) # random_nos_to_draw = 10 # main_arrow = Arrow(ORIGIN, DOWN * 1.3) # helper_arrow = Arrow(ORIGIN, LEFT * 1.3) # # for i in range(random_nos_to_draw): # num: float = np.random.random_sample(1) # point = number_line.number_to_point(num) # arrow_colour = self._apple_colour if num <= self._apple_fraction else self._banana_colour # arrow_recipient = get_apple_text if num <= self._apple_fraction else get_banana_text # # main_arrow.set_color(arrow_colour) # # if i == 0: # main_arrow.next_to(point, UP) # helper_arrow.next_to(arrow_recipient, RIGHT) # self.play(GrowArrow(main_arrow), GrowArrow(helper_arrow)) # else: # self.play(ApplyMethod(helper_arrow.next_to, arrow_recipient, RIGHT), # ApplyMethod(main_arrow.next_to, point, UP)) # self.wait() # # self.play(FadeOut(main_arrow), FadeOut(helper_arrow)) self.wait()
def scroll_through_patrons(self): logo_box = Square(side_length=2.5) logo_box.to_corner(DOWN + LEFT, buff=MED_LARGE_BUFF) total_width = FRAME_X_RADIUS - logo_box.get_right()[0] black_rect = Rectangle( fill_color=BLACK, fill_opacity=1, stroke_width=3, stroke_color=BLACK, width=FRAME_WIDTH, height=0.6 * FRAME_HEIGHT, ) black_rect.to_edge(UP, buff=0) line = DashedLine(FRAME_X_RADIUS * LEFT, FRAME_X_RADIUS * RIGHT) line.move_to(ORIGIN) thanks = TextMobject(self.thanks_words) thanks.scale(0.9) thanks.next_to(black_rect.get_bottom(), UP, SMALL_BUFF) thanks.set_color(YELLOW) underline = Line(LEFT, RIGHT) underline.match_width(thanks) underline.scale(1.1) underline.next_to(thanks, DOWN, SMALL_BUFF) thanks.add(underline) changed_patron_names = map( self.modify_patron_name, self.specific_patrons, ) patrons = VGroup(*map( TextMobject, changed_patron_names, )) patrons.scale(self.patron_scale_val) for patron in patrons: if patron.get_width() > self.max_patron_width: patron.set_width(self.max_patron_width) columns = VGroup(*[ VGroup(*patrons[i::self.n_patron_columns]) for i in range(self.n_patron_columns) ]) for column in columns: for n, name in enumerate(column): name.shift(n * self.name_y_spacing * DOWN) columns.arrange( RIGHT, buff=LARGE_BUFF, aligned_edge=UP, ) max_width = FRAME_WIDTH - 1 if columns.get_width() > max_width: columns.set_width(max_width) underline.match_width(columns) # thanks.to_edge(RIGHT, buff=MED_SMALL_BUFF) columns.next_to(underline, DOWN, buff=2) columns.generate_target() columns.target.to_edge(DOWN, buff=2) vect = columns.target.get_center() - columns.get_center() distance = get_norm(vect) wait_time = 20 always_shift( columns, direction=normalize(vect), rate=(distance / wait_time) ) self.add(columns, black_rect, line, thanks) self.wait(wait_time)
def setup_axes(self, reback=False, animate=False): """ This method sets up the axes of the graph. Parameters ---------- animate (bool=False) Whether or not to animate the setting up of the Axes. """ # reback和animate都为True时,只有reback生效 # TODO, once eoc is done, refactor this to be less redundant. x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width / x_num_range if self.x_labeled_nums is None: self.x_labeled_nums = [] if self.x_leftmost_tick is None: self.x_leftmost_tick = self.x_min x_axis = NumberLine( x_min=self.x_min, x_max=self.x_max, unit_size=self.space_unit_to_x, tick_frequency=self.x_tick_frequency, leftmost_tick=self.x_leftmost_tick, numbers_with_elongated_ticks=self.x_labeled_nums, color=self.axes_color, stroke_opacity=self.xyStrokeOpacity, decimal_number_config={"num_decimal_places": self.x_num_decimal_places} ) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if len(self.x_labeled_nums) > 0: if self.exclude_zero_label: self.x_labeled_nums = [x for x in self.x_labeled_nums] # self.x_labeled_nums = [x for x in self.x_labeled_nums if x != 0] x_axis.add_numbers(*self.x_labeled_nums) if self.x_axis_label: x_label = TextMobject(self.x_axis_label) x_label.next_to( x_axis.get_tick_marks(), UP + RIGHT, buff=SMALL_BUFF ) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height / y_num_range if self.y_labeled_nums is None: self.y_labeled_nums = [] if self.y_bottom_tick is None: self.y_bottom_tick = self.y_min y_axis = NumberLine( x_min=self.y_min, x_max=self.y_max, unit_size=self.space_unit_to_y, tick_frequency=self.y_tick_frequency, leftmost_tick=self.y_bottom_tick, numbers_with_elongated_ticks=self.y_labeled_nums, color=self.axes_color, line_to_number_vect=LEFT, label_direction=LEFT, stroke_opacity=self.xyStrokeOpacity, decimal_number_config={"num_decimal_places": self.y_num_decimal_places} ) y_axis.shift(self.graph_origin - y_axis.number_to_point(0)) y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0)) if len(self.y_labeled_nums) > 0: if self.exclude_zero_label: self.y_labeled_nums = [y for y in self.y_labeled_nums if y != 0] y_axis.add_numbers(*self.y_labeled_nums) if self.y_axis_label: y_label = TextMobject(self.y_axis_label) y_label.next_to( y_axis.get_corner(UP + RIGHT), UP + RIGHT, buff=SMALL_BUFF ) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label # 给对象绑定x_axis和y_axis属性 # Ag 修改了reback和这里的顺序 self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis) self.default_graph_colors = it.cycle(self.default_graph_colors) if self.add_coordinate_grid: self.lines_x_axis = self.get_vertical_lines_to_axis( num_lines=len(np.arange(self.x_min, self.x_max, self.x_tick_frequency))+1 ) self.lines_y_axis = self.get_horizontal_lines_to_axis( num_lines=len(np.arange(self.y_min, self.y_max, self.y_tick_frequency))+1 ) return self.reback_or_anim_axis(reback, animate)
def scroll_through_patrons(self): logo_box = Square(side_length=2.5) logo_box.to_corner(DOWN + LEFT, buff=MED_LARGE_BUFF) total_width = FRAME_X_RADIUS - logo_box.get_right()[0] black_rect = Rectangle( fill_color=BLACK, fill_opacity=1, stroke_width=3, stroke_color=BLACK, width=FRAME_WIDTH, height=0.6 * FRAME_HEIGHT, ) black_rect.to_edge(UP, buff=0) line = DashedLine(FRAME_X_RADIUS * LEFT, FRAME_X_RADIUS * RIGHT) line.move_to(ORIGIN) thanks = TextMobject(self.thanks_words) thanks.scale(0.9) thanks.next_to(black_rect.get_bottom(), UP, SMALL_BUFF) thanks.set_color(YELLOW) underline = Line(LEFT, RIGHT) underline.match_width(thanks) underline.scale(1.1) underline.next_to(thanks, DOWN, SMALL_BUFF) thanks.add(underline) changed_patron_names = map( self.modify_patron_name, self.specific_patrons, ) patrons = VGroup(*map( TextMobject, changed_patron_names, )) patrons.scale(self.patron_scale_val) for patron in patrons: if patron.get_width() > self.max_patron_width: patron.set_width(self.max_patron_width) columns = VGroup(*[ VGroup(*patrons[i::self.n_patron_columns]) for i in range(self.n_patron_columns) ]) for column in columns: for n, name in enumerate(column): name.shift(n * self.name_y_spacing * DOWN) columns.arrange( RIGHT, buff=LARGE_BUFF, aligned_edge=UP, ) if columns.get_width() > self.max_patron_width: columns.set_width(total_width - 1) thanks.to_edge(RIGHT, buff=MED_SMALL_BUFF) columns.next_to(underline, DOWN, buff=2) columns.generate_target() columns.target.to_edge(DOWN, buff=2) vect = columns.target.get_center() - columns.get_center() distance = get_norm(vect) wait_time = 20 always_shift( columns, direction=normalize(vect), rate=(distance / wait_time) ) self.add(columns, black_rect, line, thanks) self.wait(wait_time)
def setup_axes(self, animate=False): """ Creates two axes according to the parameters in CONFIG """ # TODO, once eoc is done, refactor this to be less redundant. x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width / x_num_range if self.x_labeled_nums is None: self.x_labeled_nums = [] if self.x_leftmost_tick is None: self.x_leftmost_tick = self.x_min x_axis = NumberLine(x_min=self.x_min, x_max=self.x_max, unit_size=self.space_unit_to_x, tick_frequency=self.x_tick_frequency, leftmost_tick=self.x_leftmost_tick, numbers_with_elongated_ticks=self.x_labeled_nums, color=self.axes_color) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if len(self.x_labeled_nums) > 0: if self.exclude_zero_label: self.x_labeled_nums = [ x for x in self.x_labeled_nums if x != 0 ] x_axis.add_numbers(*self.x_labeled_nums) if self.x_axis_label: x_label = TextMobject(self.x_axis_label) x_label.next_to(x_axis.get_tick_marks(), UP + RIGHT, buff=SMALL_BUFF) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height / y_num_range if self.y_labeled_nums is None: self.y_labeled_nums = [] if self.y_bottom_tick is None: self.y_bottom_tick = self.y_min y_axis = NumberLine( x_min=self.y_min, x_max=self.y_max, unit_size=self.space_unit_to_y, tick_frequency=self.y_tick_frequency, leftmost_tick=self.y_bottom_tick, numbers_with_elongated_ticks=self.y_labeled_nums, color=self.axes_color, line_to_number_vect=LEFT, label_direction=LEFT, ) y_axis.shift(self.graph_origin - y_axis.number_to_point(0)) y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0)) if len(self.y_labeled_nums) > 0: if self.exclude_zero_label: self.y_labeled_nums = [ y for y in self.y_labeled_nums if y != 0 ] y_axis.add_numbers(*self.y_labeled_nums) if self.y_axis_label: y_label = TextMobject(self.y_axis_label) y_label.next_to(y_axis.get_corner(UP + RIGHT), UP + RIGHT, buff=SMALL_BUFF) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label if animate: self.play(Write(VGroup(x_axis, y_axis))) else: self.add(x_axis, y_axis) self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis) self.default_graph_colors = it.cycle(self.default_graph_colors)
def construct(self): # Add title title = self.title = TextMobject("Clicky Stuffs") title.scale(1.5) title.to_edge(UP, buff=MED_SMALL_BUFF) pi_creatures = VGroup(Randolph(), Mortimer()) for pi, vect in zip(pi_creatures, [LEFT, RIGHT]): pi.set_height(title.get_height()) pi.change_mode("thinking") pi.look(DOWN) pi.next_to(title, vect, buff=MED_LARGE_BUFF) self.add(title, pi_creatures) # Set the top of the screen logo_box = Square(side_length=2.5) logo_box.to_corner(DOWN + LEFT, buff=MED_LARGE_BUFF) black_rect = Rectangle( fill_color=BLACK, fill_opacity=1, stroke_width=3, stroke_color=BLACK, width=FRAME_WIDTH, height=0.6 * FRAME_HEIGHT, ) black_rect.to_edge(UP, buff=0) line = DashedLine(FRAME_X_RADIUS * LEFT, FRAME_X_RADIUS * RIGHT) line.move_to(ORIGIN) # Add thanks thanks = TextMobject(self.thanks_words) thanks.scale(0.9) thanks.next_to(black_rect.get_bottom(), UP, SMALL_BUFF) thanks.set_color(YELLOW) underline = Line(LEFT, RIGHT) underline.match_width(thanks) underline.scale(1.1) underline.next_to(thanks, DOWN, SMALL_BUFF) thanks.add(underline) # Build name list file_name = os.path.join(get_directories()["data"], "patrons.txt") with open(file_name, "r") as fp: names = [ self.modify_patron_name(name.strip()) for name in fp.readlines() ] if self.randomize_order: random.shuffle(names) else: names.sort() name_labels = VGroup(*map(TextMobject, names)) name_labels.scale(self.patron_scale_val) for label in name_labels: if label.get_width() > self.max_patron_width: label.set_width(self.max_patron_width) columns = VGroup(*[ VGroup(*name_labels[i::self.n_patron_columns]) for i in range(self.n_patron_columns) ]) column_x_spacing = 0.5 + max([c.get_width() for c in columns]) for i, column in enumerate(columns): for n, name in enumerate(column): name.shift(n * self.name_y_spacing * DOWN) name.align_to(ORIGIN, LEFT) column.move_to(i * column_x_spacing * RIGHT, UL) columns.center() max_width = FRAME_WIDTH - 1 if columns.get_width() > max_width: columns.set_width(max_width) underline.match_width(columns) columns.next_to(underline, DOWN, buff=3) # Set movement columns.generate_target() distance = columns.get_height() + 2 wait_time = self.scroll_time frame = self.camera.frame frame_shift = ApplyMethod( frame.shift, distance * DOWN, run_time=wait_time, rate_func=linear, ) blink_anims = [] blank_mob = Mobject() for x in range(wait_time): if random.random() < 0.25: blink_anims.append(Blink(random.choice(pi_creatures))) else: blink_anims.append(Animation(blank_mob)) blinks = Succession(*blink_anims) static_group = VGroup(black_rect, line, thanks, pi_creatures, title) static_group.fix_in_frame() self.add(columns, static_group) self.play(frame_shift, blinks)
def setup_axes(self, animate=False): # X axis --------------------- x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width / x_num_range if self.x_labeled_nums is None: self.x_labeled_nums = [] if self.x_elongated_nums is None: self.x_elongated_nums = [] if self.x_leftmost_tick is None: self.x_leftmost_tick = self.x_min x_axis = NumberLine(x_min=self.x_min, x_max=self.x_max, unit_size=self.space_unit_to_x, tick_frequency=self.x_tick_frequency, leftmost_tick=self.x_leftmost_tick, numbers_with_elongated_ticks=self.x_elongated_nums, color=self.axes_color) if len(self.x_labeled_nums) > 0: if self.exclude_zero_label: self.x_labeled_nums = [ x for x in self.x_labeled_nums if x != 0 ] x_axis.add_numbers(*self.x_labeled_nums) if self.x_axis_label: x_label = TextMobject(self.x_axis_label) x_label.next_to( x_axis.get_corner(self.x_axis_label_position), self.x_axis_label_position, buff=self.x_axis_label_buff, ) x_axis.add(x_label) self.x_axis_label_mob = x_label # Y axis --------------------- y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height / y_num_range if self.y_labeled_nums is None: self.y_labeled_nums = [] if self.y_elongated_nums is None: self.y_elongated_nums = [] if self.y_bottom_tick is None: self.y_bottom_tick = self.y_min y_axis = NumberLine( x_min=self.y_min, x_max=self.y_max, unit_size=self.space_unit_to_y, tick_frequency=self.y_tick_frequency, leftmost_tick=self.y_bottom_tick, numbers_with_elongated_ticks=self.y_elongated_nums, color=self.axes_color, label_direction=LEFT, ) y_axis.shift(-1 * y_axis.number_to_point(0)) y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0)) if len(self.y_labeled_nums) > 0: if self.exclude_zero_label: self.y_labeled_nums = [ y for y in self.y_labeled_nums if y != 0 ] y_axis.add_numbers(*self.y_labeled_nums) if self.y_axis_label: y_label = TextMobject(self.y_axis_label) y_label.next_to( y_axis.get_corner(self.y_axis_label_position), self.y_axis_label_position, buff=self.y_axis_label_buff, ) y_axis.add(y_label) self.y_axis_label_mob = y_label # Add axes self.add(x_axis, y_axis) self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis) self.default_graph_colors = it.cycle(self.default_graph_colors)
def setup_axes(self, animate=False): # TODO, once eoc is done, refactor this to be less redundant. x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width / x_num_range if self.x_labeled_nums is None: self.x_labeled_nums = [] if self.x_leftmost_tick is None: self.x_leftmost_tick = self.x_min x_axis = NumberLine( x_min=self.x_min, x_max=self.x_max, unit_size=self.space_unit_to_x, tick_frequency=self.x_tick_frequency, leftmost_tick=self.x_leftmost_tick, numbers_with_elongated_ticks=self.x_labeled_nums, color=self.axes_color ) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if len(self.x_labeled_nums) > 0: if self.exclude_zero_label: self.x_labeled_nums = [x for x in self.x_labeled_nums if x != 0] x_axis.add_numbers(*self.x_labeled_nums) if self.x_axis_label: x_label = TextMobject(self.x_axis_label) x_label.next_to( x_axis.get_tick_marks(), UP + RIGHT, buff=SMALL_BUFF ) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height / y_num_range if self.y_labeled_nums is None: self.y_labeled_nums = [] if self.y_bottom_tick is None: self.y_bottom_tick = self.y_min y_axis = NumberLine( x_min=self.y_min, x_max=self.y_max, unit_size=self.space_unit_to_y, tick_frequency=self.y_tick_frequency, leftmost_tick=self.y_bottom_tick, numbers_with_elongated_ticks=self.y_labeled_nums, color=self.axes_color, line_to_number_vect=LEFT, label_direction=LEFT, ) y_axis.shift(self.graph_origin - y_axis.number_to_point(0)) y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0)) if len(self.y_labeled_nums) > 0: if self.exclude_zero_label: self.y_labeled_nums = [y for y in self.y_labeled_nums if y != 0] y_axis.add_numbers(*self.y_labeled_nums) if self.y_axis_label: y_label = TextMobject(self.y_axis_label) y_label.next_to( y_axis.get_corner(UP + RIGHT), UP + RIGHT, buff=SMALL_BUFF ) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label if animate: self.play(Write(VGroup(x_axis, y_axis))) else: self.add(x_axis, y_axis) self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis) self.default_graph_colors = it.cycle(self.default_graph_colors)