Ejemplo n.º 1
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()
Ejemplo n.º 2
0
    def __init__(self, vmobject, **kwargs):
        if not hasattr(self, "args"):
            self.args = serialize_args([vmobject])
        if not hasattr(self, "config"):
            self.config = serialize_config({
                **kwargs,
            })
        VMobject.__init__(self, **kwargs)
        num_dashes = self.num_dashes
        ps_ratio = self.positive_space_ratio
        if num_dashes > 0:
            # End points of the unit interval for division
            alphas = np.linspace(0, 1, num_dashes + 1)

            # This determines the length of each "dash"
            full_d_alpha = (1.0 / num_dashes)
            partial_d_alpha = full_d_alpha * ps_ratio

            # Rescale so that the last point of vmobject will
            # be the end of the last dash
            alphas /= (1 - full_d_alpha + partial_d_alpha)

            self.add(*[
                vmobject.get_subcurve(alpha, alpha + partial_d_alpha)
                for alpha in alphas[:-1]
            ])
        # Family is already taken care of by get_subcurve
        # implementation
        self.match_style(vmobject, family=False)
Ejemplo n.º 3
0
    def __init__(self, *tex_strings, **kwargs):
        #### EULERTOUR_INIT_START ####
        if not hasattr(self, "args"):
            self.args = serialize_args(tex_strings)
        if not hasattr(self, "config"):
            self.config = serialize_config({
                **kwargs,
            })
        #### EULERTOUR_INIT_START ####
        digest_config(self, kwargs)
        tex_strings = self.break_up_tex_strings(tex_strings)
        self.tex_strings = tex_strings
        SingleStringTexMobject.__init__(self,
                                        self.arg_separator.join(tex_strings),
                                        skip_registration=True,
                                        **kwargs)
        self.skip_registration = False
        self.break_up_by_substrings()
        self.set_color_by_tex_to_color_map(self.tex_to_color_map)

        if self.organize_left_to_right:
            self.organize_submobjects_left_to_right()
        if hasattr(self, 'kwargs'):
            self.kwargs = {
                'tex_strings': self.tex_strings,
                **kwargs,
                **self.kwargs
            }
        else:
            self.kwargs = {'tex_strings': self.tex_strings, **kwargs}
        #### EULERTOUR_INIT_END ####
        register_mobject(self)
Ejemplo n.º 4
0
    def __init__(self, mobject, direction=DOWN, **kwargs):
        if not hasattr(self, "args"):
            self.args = serialize_args([mobject])
        if not hasattr(self, "config"):
            self.config = serialize_config({
                'direction': direction,
                **kwargs,
            })
        digest_config(self, kwargs, locals())
        angle = -np.arctan2(*direction[:2]) + np.pi
        mobject.rotate(-angle, about_point=ORIGIN)
        left = mobject.get_corner(DOWN + LEFT)
        right = mobject.get_corner(DOWN + RIGHT)
        target_width = right[0] - left[0]

        # Adding int(target_width) qquads gives approximately the right width
        num_quads = np.clip(int(self.width_multiplier * target_width),
                            self.min_num_quads, self.max_num_quads)
        tex_string = "\\underbrace{%s}" % (num_quads * "\\qquad")
        TexMobject.__init__(self, tex_string, **kwargs)
        self.tip_point_index = np.argmin(self.get_all_points()[:, 1])
        self.stretch_to_fit_width(target_width)
        self.shift(left - self.get_corner(UP + LEFT) + self.buff * DOWN)
        for mob in mobject, self:
            mob.rotate(angle, about_point=ORIGIN)
Ejemplo n.º 5
0
    def __init__(self, start_anim, end_anim, **kwargs):
        if not hasattr(self, "args"):
            self.args = serialize_args([start_anim, end_anim])
        if not hasattr(self, "config"):
            self.config = serialize_config({
                **kwargs,
            })
        digest_config(self, kwargs, locals())
        if "run_time" in kwargs:
            self.run_time = kwargs.pop("run_time")
        else:
            self.run_time = max(start_anim.run_time, end_anim.run_time)
        for anim in start_anim, end_anim:
            anim.set_run_time(self.run_time)

        if start_anim.starting_mobject.get_num_points(
        ) != end_anim.starting_mobject.get_num_points():
            start_anim.starting_mobject.align_data(end_anim.starting_mobject)
            for anim in start_anim, end_anim:
                if hasattr(anim, "target_mobject"):
                    anim.starting_mobject.align_data(anim.target_mobject)

        Transform.__init__(self, start_anim.mobject, end_anim.mobject,
                           **kwargs)
        # Rewire starting and ending mobjects
        start_anim.mobject = self.starting_mobject
        end_anim.mobject = self.target_mobject
Ejemplo n.º 6
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,
         })
     if hasattr(self, 'kwargs'):
         self.kwargs = { **kwargs, **self.kwargs }
     else:
         self.kwargs = kwargs
     #### EULERTOUR_INIT_START ####
     self.transformations = []
     Container.__init__(self, **kwargs)
     self.submobjects = []
     self.color = Color(self.color)
     if self.name is None:
         self.name = self.__class__.__name__
     self.updaters = []
     self.updating_suspended = False
     self.reset_points()
     self.generate_points()
     self.init_colors()
     if 'template_tex_file_body' in self.kwargs:
         del self.kwargs['template_tex_file_body']
     #### EULERTOUR_INIT_END ####
     if "skip_registration" not in kwargs or not kwargs["skip_registration"]:
         register_mobject(self)
Ejemplo n.º 7
0
 def __init__(self, mobject, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([mobject])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     super().__init__(ShowCreation(mobject), FadeOut(mobject), **kwargs)
Ejemplo n.º 8
0
 def __init__(self, filename_or_array, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([filename_or_array])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     raise NotImplementedError('not available in javascript')
Ejemplo n.º 9
0
 def __init__(self, mobject, scale_factor, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([mobject, scale_factor])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     super().__init__(mobject.scale, scale_factor, **kwargs)
Ejemplo n.º 10
0
 def __init__(self, mobject, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([mobject])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     super().__init__(mobject.restore, **kwargs)
Ejemplo n.º 11
0
 def __init__(self, arrow, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([arrow])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     point = arrow.get_start()
     super().__init__(arrow, point, **kwargs)
Ejemplo n.º 12
0
    def __init__(self, **kwargs):
        if not hasattr(self, "args"):
            self.args = serialize_args([])
        if not hasattr(self, "config"):
            self.config = serialize_config({
                **kwargs,
            })
        super().__init__(**kwargs)
        body = Cube(side_length=1)
        for dim, scale_factor in enumerate(self.body_dimensions):
            body.stretch(scale_factor, dim=dim)
        body.set_width(self.width)
        body.set_fill(self.shaded_body_color, opacity=1)
        body.sort(lambda p: p[2])
        body[-1].set_fill(self.body_color)
        screen_plate = body.copy()
        keyboard = VGroup(*[
            VGroup(
                *[Square(**self.key_color_kwargs)
                  for x in range(12 - y % 2)]).arrange(RIGHT, buff=SMALL_BUFF)
            for y in range(4)
        ]).arrange(DOWN, buff=MED_SMALL_BUFF)
        keyboard.stretch_to_fit_width(
            self.keyboard_width_to_body_width * body.get_width(), )
        keyboard.stretch_to_fit_height(
            self.keyboard_height_to_body_height * body.get_height(), )
        keyboard.next_to(body, OUT, buff=0.1 * SMALL_BUFF)
        keyboard.shift(MED_SMALL_BUFF * UP)
        body.add(keyboard)

        screen_plate.stretch(self.screen_thickness / self.body_dimensions[2],
                             dim=2)
        screen = Rectangle(
            stroke_width=0,
            fill_color=BLACK,
            fill_opacity=1,
        )
        screen.replace(screen_plate, stretch=True)
        screen.scale_in_place(self.screen_width_to_screen_plate_width)
        screen.next_to(screen_plate, OUT, buff=0.1 * SMALL_BUFF)
        screen_plate.add(screen)
        screen_plate.next_to(body, UP, buff=0)
        screen_plate.rotate(self.open_angle,
                            RIGHT,
                            about_point=screen_plate.get_bottom())
        self.screen_plate = screen_plate
        self.screen = screen

        axis = Line(body.get_corner(UP + LEFT + OUT),
                    body.get_corner(UP + RIGHT + OUT),
                    color=BLACK,
                    stroke_width=2)
        self.axis = axis

        self.add(body, screen_plate, axis)
        self.rotate(5 * np.pi / 12, LEFT, about_point=ORIGIN)
        self.rotate(np.pi / 6, DOWN, about_point=ORIGIN)
Ejemplo n.º 13
0
 def __init__(self, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     Bubble.__init__(self, **kwargs)
     self.submobjects.sort(key=lambda m: m.get_bottom()[1])
Ejemplo n.º 14
0
 def __init__(self, camera, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([camera])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     self.camera = camera
     AbstractImageMobject.__init__(self, **kwargs)
Ejemplo n.º 15
0
 def __init__(self, key=None, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             'key': key,
             **kwargs,
         })
     VGroup.__init__(self, key=key, **kwargs)
Ejemplo n.º 16
0
 def __init__(self, mobject, update_function, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([mobject, update_function])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     self.update_function = update_function
     super().__init__(mobject, **kwargs)
Ejemplo n.º 17
0
 def __init__(self, mobject, edge, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([mobject, edge])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     point = mobject.get_critical_point(edge)
     super().__init__(mobject, point, **kwargs)
Ejemplo n.º 18
0
 def __init__(self, mobject, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([mobject])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     SurroundingRectangle.__init__(self, mobject, **kwargs)
     self.original_fill_opacity = self.fill_opacity
Ejemplo n.º 19
0
 def __init__(self, mobject, path, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([mobject, path])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     self.path = path
     super().__init__(mobject, **kwargs)
Ejemplo n.º 20
0
 def __init__(self, vmobject, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([vmobject])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     self.check_validity_of_input(vmobject)
     super().__init__(vmobject, **kwargs)
Ejemplo n.º 21
0
 def __init__(self, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     Rectangle.__init__(self, **kwargs)
     self.set_width(self.aspect_ratio * self.get_height(), stretch=True)
Ejemplo n.º 22
0
 def __init__(self, group, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([group])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     self.all_submobs = list(group.submobjects)
     super().__init__(group, **kwargs)
Ejemplo n.º 23
0
 def __init__(self, group, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([group])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     new_group = Group(*group)
     super().__init__(new_group, **kwargs)
Ejemplo n.º 24
0
 def __init__(self, *mobjects, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args(mobjects)
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     self.group = Group(*mobjects)
     super().__init__(self.group, **kwargs)
Ejemplo n.º 25
0
 def __init__(self, function, mobject, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([function, mobject])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     self.function = function
     super().__init__(mobject, **kwargs)
Ejemplo n.º 26
0
 def __init__(self, mobject, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([mobject])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     digest_config(self, kwargs)
     self.set_default_config_from_length(mobject)
     super().__init__(mobject, **kwargs)
Ejemplo n.º 27
0
 def __init__(self, mobject, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([mobject])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     super().__init__(LEFT, RIGHT, **kwargs)
     self.match_width(mobject)
     self.next_to(mobject, DOWN, buff=self.buff)
Ejemplo n.º 28
0
 def __init__(self, location=ORIGIN, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             'location': location,
             **kwargs,
         })
     VMobject.__init__(self, **kwargs)
     self.set_points(np.array([location]))
Ejemplo n.º 29
0
 def __init__(self, mobject, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([mobject])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     assert (isinstance(mobject, Mobject))
     digest_config(self, kwargs)
     self.mobject = mobject
Ejemplo n.º 30
0
 def __init__(self, car, target_point, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([car, target_point])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     self.check_if_input_is_car(car)
     self.target_point = target_point
     super().__init__(car.move_to, target_point, **kwargs)