def __init__(self, mobject, **kwargs): digest_config(self, kwargs) rect = SurroundingRectangle(mobject, **self.surrounding_rectangle_config) if "surrounding_rectangle_config" in kwargs: kwargs.pop("surrounding_rectangle_config") AnimationGroup.__init__(self, self.rect_to_animation(rect, **kwargs))
def construct(self): square = Square(side_length=5, fill_color=YELLOW, fill_opacity=1) label = TextMobject("Text at an angle") label_bg = BackgroundRectangle(label, fill_opacity=1) label_group = VGroup(label_bg, label) label_group.rotate(TAU / 8) label2 = TextMobject("Boxed text", color=BLACK) label2_bg = SurroundingRectangle(label2, color=BLUE, fill_color=RED, fill_opacity=.5) label2_group = VGroup(label2, label2_bg) label2_group.next_to(label_group, DOWN) label3 = TextMobject("Rainbow") label3.scale(2) label3.set_color_by_gradient(RED, GREEN, BLUE) label3.to_edge(DOWN) self.add(square) self.play(FadeIn(label_group)) self.play(FadeIn(label2_group)) self.play(FadeIn(label3)) self.wait(2)
def __init__(self, file_name=None, **kwargs): Container.__init__(self, **kwargs) self.file_name = file_name or self.file_name self.ensure_valid_file() self.style = self.style.lower() self.gen_html_string() strati = self.html_string.find("background:") self.background_color = self.html_string[strati + 12:strati + 19] self.gen_code_json() self.code = self.gen_colored_lines() if self.insert_line_no: self.line_numbers = self.gen_line_numbers() self.line_numbers.next_to(self.code, direction=LEFT, buff=self.line_no_buff) if self.background == "rectangle": if self.insert_line_no: forground = VGroup(self.code, self.line_numbers) else: forground = self.code self.background_mobject = SurroundingRectangle(forground, buff=self.margin, color=self.background_color, fill_color=self.background_color, stroke_width=0, fill_opacity=1, ) self.background_mobject.round_corners(self.corner_radius) else: if self.insert_line_no: forground = VGroup(self.code, self.line_numbers) else: forground = self.code height = forground.get_height() + 0.1 * 3 + 2 * self.margin width = forground.get_width() + 0.1 * 3 + 2 * self.margin rrect = RoundedRectangle(corner_radius=self.corner_radius, height=height, width=width, stroke_width=0, color=self.background_color, fill_opacity=1) button_radius = 0.09 red_button = Dot(radius=button_radius, stroke_width=0, color='#ff5f56') red_button.shift(LEFT * button_radius * 3) yellow_button = Dot(radius=button_radius, stroke_width=0, color='#ffbd2e') green_button = Dot(radius=button_radius, stroke_width=0, color='#27c93f') green_button.shift(RIGHT * button_radius * 3) buttons = VGroup(red_button, yellow_button, green_button) buttons.shift( UP * (height / 2 - 0.1 * 2 - 0.05) + LEFT * (width / 2 - 0.1 * 5 - self.corner_radius / 2 - 0.05)) self.background_mobject = VGroup(rrect, buttons) x = (height - forground.get_height()) / 2 - 0.1 * 3 self.background_mobject.shift(forground.get_center()) self.background_mobject.shift(UP * x) if self.insert_line_no: VGroup.__init__(self, self.background_mobject, self.line_numbers, *self.code, **kwargs) else: VGroup.__init__(self, self.background_mobject, Dot(fill_opacity=0, stroke_opacity=0), *self.code, **kwargs) self.move_to(np.array([0, 0, 0]))
def generate_rec(self, mobject): rectangle = SurroundingRectangle( mobject, color=self.color, fill_opacity=self.rec_opacity, stroke_width=0, buff=self.buff, ) mobject.rectangle = rectangle
def show_claim(self): lhs, equal, rhs = claim = TexMobject( "\\prod_{r=1}^{+\\infty}{\\sum_{k=0}^{+\\infty}{f(p_r^k)}", "=", "\\sum_{n=1}^{+\\infty}{f(n)}") claim.scale(1.2) claim.to_edge(UP) lhs.set_color(GREEN) rhs.set_color(BLUE) prod_tex_rect = SurroundingRectangle(self.prod_tex, color=GREEN) sum_tex_rect = SurroundingRectangle(self.sum_tex, color=BLUE) self.play( ShowCreationThenDestruction(prod_tex_rect), Write(lhs), run_time=2, ) self.play( ShowCreationThenDestruction(sum_tex_rect), Write(rhs), run_time=2, ) self.play(Write(equal)) self.wait(3)
def ask_about_how_to_prove(self): claim_text = self.q_texts[0] self.wait() self.play(self.q_texts.shift, DOWN, run_time=1) claim_rect = SurroundingRectangle(VGroup(claim_text, self.how_to_prove_text), stroke_color=YELLOW, buff=0.3) self.play( Write(self.how_to_prove_text), ShowCreation(claim_rect), run_time=1, ) self.wait() self.claim_rect = claim_rect
def get_rect(self): return SurroundingRectangle( self.mobject_to_surround, **self.surrounding_rectangle_config )
def add_display_frame(self, **kwargs): config = dict(self.default_display_frame_config) config.update(kwargs) self.display_frame = SurroundingRectangle(self, **config) self.add(self.display_frame) return self
def get_highlight_rectangle(self, term_tex, k): return SurroundingRectangle(self.get_highlighted_term(term_tex, k))
def get_path(self, mobject: Mobject) -> SurroundingRectangle: return SurroundingRectangle(mobject, buff=self.buff)
def __init__(self, file_name=None, code_str=None, **kwargs): Container.__init__(self, **kwargs) self.file_name = file_name self.code_str = code_str self.ensure_valid_file() self.style = self.style.lower() self.gen_html_string() strati = self.html_string.find("background:") self.background_color = self.html_string[strati + 12:strati + 19] self.gen_code_json() self.code = self.gen_colored_lines() if self.insert_line_no: self.line_numbers = self.gen_line_numbers() self.line_numbers.next_to(self.code, direction=LEFT, buff=self.line_no_buff) if self.background == "rectangle": if self.insert_line_no: forground = VGroup(self.code, self.line_numbers) else: forground = self.code self.background_mobject = SurroundingRectangle( forground, buff=self.margin, color=self.background_color, fill_color=self.background_color, stroke_width=0, fill_opacity=1, ) self.background_mobject.round_corners(self.corner_radius) else: if self.insert_line_no: forground = VGroup(self.code, self.line_numbers) else: forground = self.code height = forground.get_height() + 0.1 * 3 + 2 * self.margin width = forground.get_width() + 0.1 * 3 + 2 * self.margin rrect = RoundedRectangle(corner_radius=self.corner_radius, height=height, width=width, stroke_width=0, color=GREY_E, fill_opacity=1) red_button = Dot(radius=0.1, stroke_width=0, color='#ff5f56') red_button.shift(LEFT * 0.1 * 3) yellow_button = Dot(radius=0.1, stroke_width=0, color='#ffbd2e') green_button = Dot(radius=0.1, stroke_width=0, color='#27c93f') green_button.shift(RIGHT * 0.1 * 3) buttons = VGroup(red_button, yellow_button, green_button) buttons.shift( UP * (height / 2 - 0.1 * 2 - 0.05) + LEFT * (width / 2 - 0.1 * 5 - self.corner_radius / 2 - 0.05)) self.background_mobject = VGroup(rrect, buttons) x = (height - forground.get_height()) / 2 - 0.1 * 3 self.background_mobject.shift(forground.get_center()) self.background_mobject.shift(UP * x) if self.insert_line_no: VGroup.__init__(self, self.background_mobject, self.line_numbers, *self.code, **kwargs) else: VGroup.__init__(self, self.background_mobject, Dot(fill_opacity=0, stroke_opacity=0), *self.code, **kwargs) window = RIGHT_SIDE[0] - LEFT_SIDE[0] width = self.background_mobject.get_width() print(width) scale_x = window / width * 0.96 window = TOP[1] - BOTTOM[1] print(window) width = self.background_mobject.get_height() scale_y = window / width * 0.96 if self.adapting_x and scale_x < scale_y: self.scale(scale_x) if self.adapting_y and scale_y <= scale_x: self.scale(scale_y) self.align_to(LEFT_SIDE + self.margin, LEFT) self.align_to( TOP - self.margin + 0.42 * (self.code.char_height + self.code.line_spacing) * self.scale_factor, UP)