def __init__(self, focus_point: Union[np.ndarray, Mobject], opacity: float = 0.2, color: str = GREY, run_time: float = 2, **kwargs) -> None: self.focus_point = focus_point self.color = color self.opacity = opacity remover = True starting_dot = Dot( radius=config["frame_x_radius"] + config["frame_y_radius"], stroke_width=0, fill_color=self.color, fill_opacity=0, ) super().__init__(starting_dot, run_time=run_time, remover=remover, **kwargs)
def __init__( self, line1: Line, line2: Line, radius: float = None, quadrant=(1, 1), other_angle: bool = False, dot=False, dot_radius=None, dot_distance=0.55, dot_color=WHITE, elbow=False, **kwargs, ): super().__init__(**kwargs) self.lines = (line1, line2) self.quadrant = quadrant self.dot_distance = dot_distance self.elbow = elbow inter = line_intersection( [line1.get_start(), line1.get_end()], [line2.get_start(), line2.get_end()], ) if radius is None: if quadrant[0] == 1: dist_1 = np.linalg.norm(line1.get_end() - inter) else: dist_1 = np.linalg.norm(line1.get_start() - inter) if quadrant[1] == 1: dist_2 = np.linalg.norm(line2.get_end() - inter) else: dist_2 = np.linalg.norm(line2.get_start() - inter) if np.minimum(dist_1, dist_2) < 0.6: radius = (2 / 3) * np.minimum(dist_1, dist_2) else: radius = 0.4 else: self.radius = radius anchor_angle_1 = inter + quadrant[0] * radius * line1.get_unit_vector() anchor_angle_2 = inter + quadrant[1] * radius * line2.get_unit_vector() if elbow: anchor_middle = (inter + quadrant[0] * radius * line1.get_unit_vector() + quadrant[1] * radius * line2.get_unit_vector()) angle_mobject = Elbow(**kwargs) angle_mobject.set_points_as_corners( [anchor_angle_1, anchor_middle, anchor_angle_2], ) else: angle_1 = angle_of_vector(anchor_angle_1 - inter) angle_2 = angle_of_vector(anchor_angle_2 - inter) if not other_angle: start_angle = angle_1 if angle_2 > angle_1: angle_fin = angle_2 - angle_1 else: angle_fin = 2 * np.pi - (angle_1 - angle_2) else: start_angle = angle_1 if angle_2 < angle_1: angle_fin = -angle_1 + angle_2 else: angle_fin = -2 * np.pi + (angle_2 - angle_1) self.angle_value = angle_fin angle_mobject = Arc( radius=radius, angle=self.angle_value, start_angle=start_angle, arc_center=inter, **kwargs, ) if dot: if dot_radius is None: dot_radius = radius / 10 else: self.dot_radius = dot_radius right_dot = Dot(ORIGIN, radius=dot_radius, color=dot_color) dot_anchor = ( inter + (angle_mobject.get_center() - inter) / np.linalg.norm(angle_mobject.get_center() - inter) * radius * dot_distance) right_dot.move_to(dot_anchor) self.add(right_dot) self.set_points(angle_mobject.points)
def __init__( self, file_name=None, code=None, tab_width=3, line_spacing=0.3, font_size=24, font="Monospac821 BT", stroke_width=0, margin=0.3, indentation_chars=" ", background="rectangle", # or window background_stroke_width=1, background_stroke_color=WHITE, corner_radius=0.2, insert_line_no=True, line_no_from=1, line_no_buff=0.4, style="vim", language=None, generate_html_file=False, **kwargs, ): super().__init__( stroke_width=stroke_width, **kwargs, ) self.background_stroke_color = background_stroke_color self.background_stroke_width = background_stroke_width self.tab_width = tab_width self.line_spacing = line_spacing self.font = font self.font_size = font_size self.margin = margin self.indentation_chars = indentation_chars self.background = background self.corner_radius = corner_radius self.insert_line_no = insert_line_no self.line_no_from = line_no_from self.line_no_buff = line_no_buff self.style = style self.language = language self.generate_html_file = generate_html_file self.file_path = None self.file_name = file_name if self.file_name: self._ensure_valid_file() with open(self.file_path, encoding="utf-8") as f: self.code_string = f.read() elif code: self.code_string = code else: raise ValueError( "Neither a code file nor a code string have been specified.", ) if isinstance(self.style, str): 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: foreground = VGroup(self.code, self.line_numbers) else: foreground = self.code rect = SurroundingRectangle( foreground, buff=self.margin, color=self.background_color, fill_color=self.background_color, stroke_width=self.background_stroke_width, stroke_color=self.background_stroke_color, fill_opacity=1, ) rect.round_corners(self.corner_radius) self.background_mobject = rect else: if self.insert_line_no: foreground = VGroup(self.code, self.line_numbers) else: foreground = self.code height = foreground.height + 0.1 * 3 + 2 * self.margin width = foreground.width + 0.1 * 3 + 2 * self.margin rect = RoundedRectangle( corner_radius=self.corner_radius, height=height, width=width, stroke_width=self.background_stroke_width, stroke_color=self.background_stroke_color, color=self.background_color, 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(rect, buttons) x = (height - foreground.height) / 2 - 0.1 * 3 self.background_mobject.shift(foreground.get_center()) self.background_mobject.shift(UP * x) if self.insert_line_no: super().__init__( self.background_mobject, self.line_numbers, self.code, **kwargs ) else: super().__init__( self.background_mobject, Dot(fill_opacity=0, stroke_opacity=0), self.code, **kwargs, ) self.move_to(np.array([0, 0, 0]))
def create_target(self) -> Dot: little_dot = Dot(radius=0) little_dot.set_fill(self.color, opacity=self.opacity) little_dot.add_updater(lambda d: d.move_to(self.focus_point)) return little_dot
def __init__(self): super().__init__() self.left_dot = Dot().shift((-1, 0, 0)) self.right_dot = Dot().shift((1, 0, 0)) self.line = Line(self.left_dot, self.right_dot) self.add(self.left_dot, self.right_dot, self.line)