Example #1
0
 def __init__(self, path, partitions=10, **kwargs):
     VMobject.__init__(self, **kwargs)
     rect = Rectangle(width=path.get_width() + self.margin,
                      height=path.get_height() + self.margin)
     rect.move_to(path)
     w = rect.get_width()
     h = rect.get_height()
     alpha = w / h
     hp = int(np.ceil(partitions / (2 * (alpha + 1))))
     wp = int(np.ceil(alpha * hp))
     sides = VGroup(*[
         Line(rect.get_corner(c1), rect.get_corner(c2))
         for c1, c2 in zip([UL, UR, DR, DL], [UR, DR, DL, UL])
     ])
     total_points = []
     for side, points in zip(sides, [wp, hp, wp, hp]):
         for p in range(points):
             total_points.append(side.point_from_proportion(p / points))
     total_points.append(total_points[0])
     middle = int(np.floor(len(total_points) / 2))
     draw_points = []
     for p in range(2, middle):
         draw_points.append(total_points[-p * self.sign])
         draw_points.append(total_points[p * self.sign])
     self.set_points_smoothly(draw_points)
Example #2
0
 def __init__(self, agc1, agc2, agc3, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.agc_list = [(agc1, agc2, agc3)]
     for n in range(self.num_iter + 1):
         self.add(VGroup(*self.agc_list[-1]))
         if n != self.num_iter:
             self.update_agc_list(n)
Example #3
0
 def __init__(self, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.chess_pieces = []
     self.add_board()
     self.add_border()
     self.add_labels()
     self.set_height(self.height)
Example #4
0
 def __init__(self,
              start_angle: float = 0,
              angle: float = TAU / 4,
              **kwargs):
     self.start_angle = start_angle
     self.angle = angle
     VMobject.__init__(self, **kwargs)
Example #5
0
 def __init__(self, matrix, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([matrix])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     """
     Matrix can either either include numbres, tex_strings,
     or mobjects
     """
     VMobject.__init__(self, **kwargs)
     matrix = np.array(matrix, ndmin=1)
     mob_matrix = self.matrix_to_mob_matrix(matrix)
     self.organize_mob_matrix(mob_matrix)
     self.elements = VGroup(*mob_matrix.flatten())
     self.add(self.elements)
     self.add_brackets()
     self.center()
     self.mob_matrix = mob_matrix
     if self.add_background_rectangles_to_entries:
         for mob in self.elements:
             mob.add_background_rectangle()
     if self.include_background_rectangle:
         self.add_background_rectangle()
Example #6
0
 def __init__(self, v1=None, v2=None, start=0, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.set_points_as_corners([RIGHT, ORIGIN,  self.get_point(v1, v2)])
     self.set_width(self.width, about_point=ORIGIN)
     if start is None and v2 is not None:
         self.rotate(angle_of_vector(v1), about_point=ORIGIN)
     elif start!=0:
         self.rotate(start, about_point=ORIGIN)
Example #7
0
 def __init__(self, line, length, FW=1, angle=PI/4, **kwargs):
     VMobject.__init__(self, **kwargs)
     line = line.get_line(length/2/np.sin(angle))
     pt = line.pts(-1)
     hash = line.copy().rotate(angle, about_point=pt)
     hash.append_vectorized_mobject(
         line.copy().rotate(-angle, about_point=pt).reverse_points())
     self.append_vectorized_mobject(hash)
Example #8
0
 def __init__(self, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.init_tiles()
     self.init_pattern()
     self.init_border()
     if self.enable_shuffle:
         self.shuffle_tiles()
     self.add(self.border, self.tiles)
     self.adjust_size()
Example #9
0
    def __init__(self, *vertices, **kwargs):

        self.mobject_or_point = None
        VMobject.__init__(self, **kwargs)
        self.set_points_as_corners(
            [*vertices, vertices[0]]
        )
        if self.mobject_or_point != None:
            self.move_to(Location(self.mobject_or_point))
Example #10
0
    def __init__(self, A, O, B, **kwargs):

        VMobject.__init__(self, **kwargs)
        OA, OB = A-O, B-O
        theta = np.angle(complex(*OA[:2])/complex(*OB[:2])) # angle of OB to OA

        self.add(Arc(start_angle=Line(O, B).get_angle(), angle=theta, radius=self.radius/2,
                     stroke_width=100 * self.radius, color=self.color).set_stroke(opacity=self.opacity).move_arc_center_to(O))
        self.add(Arc(start_angle=Line(O, B).get_angle(), angle=theta, radius=self.radius,
                     stroke_width=self.stroke_width, color=self.color).move_arc_center_to(O))
Example #11
0
 def __init__(
     self,
     a0: np.ndarray,
     h0: np.ndarray,
     h1: np.ndarray,
     a1: np.ndarray,
     **kwargs
 ):
     VMobject.__init__(self, **kwargs)
     self.add_cubic_bezier_curve(a0, h0, h1, a1)
Example #12
0
 def __init__(self, **kwargs):
     digest_config(self, kwargs)
     if self.leftmost_tick is None:
         tf = self.tick_frequency
         self.leftmost_tick = tf * np.ceil(self.x_min / tf)
     VMobject.__init__(self, **kwargs)
     if self.include_tip:
         self.add_tip()
     if self.include_numbers:
         self.add_numbers()
Example #13
0
    def __init__(self, number, **kwargs):
        VMobject.__init__(self, **kwargs)
        self.number = number
        self.initial_config = kwargs

        if isinstance(number, complex):
            formatter = self.get_complex_formatter()
        else:
            formatter = self.get_formatter()
        num_string = formatter.format(number)

        rounded_num = np.round(float(number), self.num_decimal_places)
        if num_string.startswith("-") and rounded_num == 0:
            if self.include_sign:
                num_string = "+" + num_string[1:]
            else:
                num_string = num_string[1:]

        self.add(*[
            SingleStringTexMobject(char, **kwargs)
            for char in num_string
        ])

        # Add non-numerical bits
        if self.show_ellipsis:
            self.add(SingleStringTexMobject("\\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 is not None:
            self.unit_sign = SingleStringTexMobject(self.unit, color=self.color)
            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)
            elif c == ",":
                self[i].shift(self[i].get_height() * DOWN / 2)
        if self.unit and self.unit.startswith("^"):
            self.unit_sign.align_to(self, UP)
        #
        if self.include_background_rectangle:
            self.add_background_rectangle()
Example #14
0
 def __init__(self, function=None, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             'function': function,
             **kwargs,
         })
     # either get a function from __init__ or from CONFIG
     self.function = function or self.function
     VMobject.__init__(self, **kwargs)
Example #15
0
 def __init__(self, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     VMobject.__init__(self, **kwargs)
     self.add_iris_back()
     self.add_spikes()
     self.add_pupil()
Example #16
0
 def __init__(self, line, width, ccw=1, angle=PI/2, **kwargs):
     VMobject.__init__(self, **kwargs)
     if int(ccw) >= 1:
         ccw = 1
     else:
         ccw = 0
     angle = (-1)**ccw*angle
     line = line.get_line(width, 0)
     hash = line.rotate(angle, about_point=line.pts(-1)).reverse_points()
     hash.append_vectorized_mobject(hash.copy().rotate(
         angle, about_point=hash.pts(-1)).reverse_points())
     self.append_vectorized_mobject(hash)
Example #17
0
 def __init__(self, t_func, t_range=None, **kwargs):
     digest_config(self, kwargs)
     if t_range is not None:
         self.t_range[:len(t_range)] = t_range
     # To be backward compatible with all the scenes specifying t_min, t_max, step_size
     self.t_range = [
         kwargs.get("t_min", self.t_range[0]),
         kwargs.get("t_max", self.t_range[1]),
         kwargs.get("step_size", self.t_range[2]),
     ]
     self.t_func = t_func
     VMobject.__init__(self, **kwargs)
Example #18
0
 def __init__(self, points, **kwargs):
     #### EULERTOUR_INIT_START ####
     if not hasattr(self, "args"):
         self.args = serialize_args([points])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     #### EULERTOUR_INIT_START ####
     VMobject.__init__(self, **kwargs)
     self.set_points(points)
     #### EULERTOUR_INIT_END ####
     register_mobject(self)
Example #19
0
 def __init__(self, *vertices, **kwargs):
     #### EULERTOUR_INIT_START ####
     if not hasattr(self, "args"):
         self.args = serialize_args(vertices)
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     #### EULERTOUR_INIT_START ####
     VMobject.__init__(self, **kwargs)
     self.set_points_as_corners([*vertices, vertices[0]])
     #### EULERTOUR_INIT_END ####
     register_mobject(self)
Example #20
0
 def __init__(self, path_string, **kwargs):
     #### EULERTOUR_INIT_START ####
     if not hasattr(self, "args"):
         self.args = serialize_args([path_string])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     if hasattr(self, 'kwargs'):
         self.kwargs = {'path_string': path_string, **kwargs, **self.kwargs}
     else:
         self.kwargs = {'path_string': path_string, **kwargs}
     #### EULERTOUR_INIT_START ####
     digest_locals(self)
     VMobject.__init__(self, **kwargs)
Example #21
0
 def __init__(self, svg_string=None, **kwargs):
     #### EULERTOUR_INIT_START ####
     if not hasattr(self, "args"):
         self.args = serialize_args([])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             'svg_string': svg_string,
             **kwargs,
         })
     #### EULERTOUR_INIT_START ####
     digest_config(self, kwargs)
     self.svg_string = svg_string or self.svg_string
     assert (self.svg_string is not None)
     VMobject.__init__(self, **kwargs)
     self.move_into_position()
Example #22
0
    def __init__(self, **kwargs):

        digest_config(self, kwargs)
        self.pdfunction = normal_pdf
        if not self.set_up_the_bot_curve:
            self.num_of_anchor_in_bottom_curve = 0
        #determin x_max and x_min
        side_probability = (1. - self.confidence_interval) / 2
        self.x_max = self.std * (inverse_of_normal_cdf(
            side_probability + self.confidence_interval)) + self.mean
        self.x_min = self.std * (
            inverse_of_normal_cdf(side_probability)) + self.mean

        VMobject.__init__(self, **kwargs)
        self.highest_points = self.get_highest_point()
Example #23
0
 def __init__(self, **kwargs):
     #### EULERTOUR_INIT_START ####
     if not hasattr(self, "args"):
         self.args = serialize_args([])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     #### EULERTOUR_INIT_START ####
     VMobject.__init__(self, **kwargs)
     self.set_points_as_corners([UP, UP + RIGHT, RIGHT])
     self.set_width(self.width, about_point=ORIGIN)
     self.rotate(self.angle, about_point=ORIGIN)
     #### EULERTOUR_INIT_END ####
     register_mobject(self)
Example #24
0
    def __init__(self,
                 obj: VMobject | list[VMobject],
                 text: str | Iterable[str],
                 brace_direction: np.ndarray = DOWN,
                 **kwargs) -> None:
        VMobject.__init__(self, **kwargs)
        self.brace_direction = brace_direction
        if isinstance(obj, list):
            obj = VMobject(*obj)
        self.brace = Brace(obj, brace_direction, **kwargs)

        self.label = self.label_constructor(*listify(text), **kwargs)
        self.label.scale(self.label_scale)

        self.brace.put_at_tip(self.label, buff=self.label_buff)
        self.set_submobjects([self.brace, self.label])
Example #25
0
    def __init__(self, obj, text, brace_direction=DOWN, **kwargs):
        VMobject.__init__(self, **kwargs)
        self.brace_direction = brace_direction
        if isinstance(obj, list):
            obj = VMobject(*obj)
        self.brace = Brace(obj, brace_direction, **kwargs)

        if isinstance(text, tuple) or isinstance(text, list):
            self.label = self.label_constructor(*text, **kwargs)
        else:
            self.label = self.label_constructor(str(text))
        if self.label_scale != 1:
            self.label.scale(self.label_scale)

        self.brace.put_at_tip(self.label)
        self.submobjects = [self.brace, self.label]
Example #26
0
 def __init__(self, start_angle=0, angle=TAU / 4, **kwargs):
     #### EULERTOUR_INIT_START ####
     if not hasattr(self, "args"):
         self.args = serialize_args([])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             'start_angle': start_angle,
             'angle': angle,
             **kwargs,
         })
     #### EULERTOUR_INIT_START ####
     self.start_angle = start_angle
     self.angle = angle
     VMobject.__init__(self, **kwargs)
     #### EULERTOUR_INIT_END ####
     register_mobject(self)
Example #27
0
 def __init__(self, start=LEFT, end=RIGHT, **kwargs):
     #### EULERTOUR_INIT_START ####
     if not hasattr(self, "args"):
         self.args = serialize_args([])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             'start': start,
             'end': end,
             **kwargs,
         })
     #### EULERTOUR_INIT_START ####
     digest_config(self, kwargs)
     self.set_start_and_end_attrs(start, end)
     VMobject.__init__(self, **kwargs)
     #### EULERTOUR_INIT_END ####
     register_mobject(self)
Example #28
0
    def __init__(self, obj, text, brace_direction=DOWN, **kwargs):
        VMobject.__init__(self, **kwargs)
        self.brace_direction = brace_direction
        if isinstance(obj, list):
            obj = VMobject(*obj)
        self.brace = Brace(obj, brace_direction, **kwargs)

        if isinstance(text, tuple) or isinstance(text, list):
            self.label = self.label_constructor(*text, **kwargs)
        else:
            self.label = self.label_constructor(str(text))
        if self.label_scale != 1:
            self.label.scale(self.label_scale)

        self.brace.put_at_tip(self.label)
        self.submobjects = [self.brace, self.label]
Example #29
0
 def __init__(self, line, count=1, posratio=0.5, length=0.3, space=0.1, **kwargs):
     VMobject.__init__(self, **kwargs)
     if not isinstance(line, VGroup):
         if line.get_length() <= length*5:
             length = min(max(0.15, line.get_length()/5), 0.3)
         hash = self.dimhash(line, length)
         hashmark = VMobject()
         for i in range(count):
             hashmark.append_vectorized_mobject(hash.copy().move_to(
                 i*space*line.get_unit_vector()
             ))
         self.append_vectorized_mobject(hashmark.move_to(
             line.point_from_proportion(posratio)))
     else:
         kwargs["dimhash"] = self.dimhash
         self.add(Hashs(line, count=count, posratio=posratio,
                        length=length, space=space, **kwargs))
Example #30
0
    def __init__(self, chem, name, name_direction=DOWN, **kwargs):

        VMobject.__init__(self, **kwargs)

        if isinstance(chem, ChemObject):
            self.chem = chem
        else:
            self.chem = ChemObject(chem, **kwargs)

        if isinstance(name, self.label_constructor):
            self.name = name
        else:
            self.name = self.label_constructor(name, **kwargs)

        self.name.next_to(self.chem, name_direction, buff=self.buff)

        self.submobjects = [self.chem, self.name]
Example #31
0
 def __init__(self, tex_string, **kwargs):
     #### EULERTOUR_INIT_START ####
     if not hasattr(self, "args"):
         self.args = serialize_args([tex_string])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     if hasattr(self, 'kwargs'):
         self.kwargs = {'tex_string': tex_string, **kwargs, **self.kwargs}
     else:
         self.kwargs = {'tex_string': tex_string, **kwargs}
     #### EULERTOUR_INIT_START ####
     digest_config(self, kwargs)
     assert (isinstance(tex_string, str))
     self.tex_string = tex_string
     VMobject.__init__(self, **kwargs)
Example #32
0
 def __init__(self, matrix, **kwargs):
     """
     Matrix can either either include numbres, tex_strings,
     or mobjects
     """
     VMobject.__init__(self, **kwargs)
     matrix = np.array(matrix, ndmin=1)
     mob_matrix = self.matrix_to_mob_matrix(matrix)
     self.organize_mob_matrix(mob_matrix)
     self.elements = VGroup(*mob_matrix.flatten())
     self.add(self.elements)
     self.add_brackets()
     self.center()
     self.mob_matrix = mob_matrix
     if self.add_background_rectangles_to_entries:
         for mob in self.elements:
             mob.add_background_rectangle()
     if self.include_background_rectangle:
         self.add_background_rectangle()
Example #33
0
 def __init__(self, start_angle=0, angle=TAU / 4, **kwargs):
     self.start_angle = start_angle
     self.angle = angle
     VMobject.__init__(self, **kwargs)
Example #34
0
 def __init__(self, body, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.body = body
     eyes = self.create_eyes()
     self.become(eyes, copy_submobjects=False)
Example #35
0
 def __init__(self, path_string, **kwargs):
     digest_locals(self)
     VMobject.__init__(self, **kwargs)
Example #36
0
 def __init__(self, *vertices, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.set_points_as_corners(
         [*vertices, vertices[0]]
     )
Example #37
0
 def __init__(self, file_name=None, **kwargs):
     digest_config(self, kwargs)
     self.file_name = file_name or self.file_name
     self.ensure_valid_file()
     VMobject.__init__(self, **kwargs)
     self.move_into_position()
Example #38
0
 def __init__(self, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.add_iris_back()
     self.add_spikes()
     self.add_pupil()
Example #39
0
 def __init__(self, points, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.set_points(points)
Example #40
0
 def __init__(self, start=LEFT, end=RIGHT, **kwargs):
     digest_config(self, kwargs)
     self.set_start_and_end_attrs(start, end)
     VMobject.__init__(self, **kwargs)
Example #41
0
 def __init__(self, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.set_points_as_corners([UP, UP + RIGHT, RIGHT])
     self.set_width(self.width, about_point=ORIGIN)
     self.rotate(self.angle, about_point=ORIGIN)