Beispiel #1
0
    def __init__(self, **kwargs):
        SVGMobject.__init__(self, **kwargs)

        path = self.submobjects[0]
        subpaths = path.get_subpaths()
        path.clear_points()
        for indices in [(0, 1), (2, 3), (4, 6, 7), (5,), (8,)]:
            part = VMobject()
            for index in indices:
                part.append_points(subpaths[index])
            path.add(part)

        self.set_height(self.height)
        self.set_stroke(color=Color('WHITE'), width=0)
        self.set_fill(self.color, opacity=1)

        orientation_line = Line(self.get_left(), self.get_right())
        orientation_line.set_stroke(width=0)
        self.add(orientation_line)
        self.orientation_line = orientation_line

        for light, color in zip(self.get_lights(), self.light_colors):
            light.set_fill(color, 1)
            light.is_subpath = False

        self.add_treds_to_tires()
Beispiel #2
0
    def scale(self, factor, **kwargs):
        if self.get_length() == 0:
            return self

        has_tip = self.has_tip()
        has_start_tip = self.has_start_tip()
        if has_tip or has_start_tip:
            old_tips = self.pop_tips()

        VMobject.scale(self, factor, **kwargs)
        self.set_stroke_width_from_length()

        # So horribly confusing, must redo
        if has_tip:
            self.add_tip()
            old_tips[0].points[:, :] = self.tip.points
            self.remove(self.tip)
            self.tip = old_tips[0]
            self.add(self.tip)
        if has_start_tip:
            self.add_tip(at_start=True)
            old_tips[1].points[:, :] = self.start_tip.points
            self.remove(self.start_tip)
            self.start_tip = old_tips[1]
            self.add(self.start_tip)
        return self
Beispiel #3
0
    def __init__(self, obj, text, brace_direction=consts.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]
Beispiel #4
0
 def shift_brace(self, obj, **kwargs):
     if isinstance(obj, list):
         obj = VMobject(*obj)
     self.brace = Brace(obj, self.brace_direction, **kwargs)
     self.brace.put_at_tip(self.label)
     self.submobjects[0] = self.brace
     return self
Beispiel #5
0
 def set_style_data(self,
                    stroke_color=None,
                    stroke_width=None,
                    fill_color=None,
                    fill_opacity=None,
                    family=True
                    ):
     # Unchangable style, except for fill_opacity
     VMobject.set_style_data(
         self,
         stroke_color=Color('BLACK'),
         stroke_width=0,
         fill_color=Color('BLACK'),
         fill_opacity=fill_opacity
     )
     return self
Beispiel #6
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()
Beispiel #7
0
    def __init__(self, func, **kwargs):
        VGroup.__init__(self, **kwargs)
        self.func = func
        dt = self.dt

        start_points = self.get_start_points(
            **self.start_points_generator_config
        )
        for point in start_points:
            points = [point]
            for t in np.arange(0, self.virtual_time, dt):
                last_point = points[-1]
                points.append(last_point + dt * func(last_point))
                if get_norm(last_point) > self.cutoff_norm:
                    break
            line = VMobject()
            step = max(1, int(len(points) / self.n_anchors_per_line))
            line.set_points_smoothly(points[::step])
            self.add(line)

        self.set_stroke(self.stroke_color, self.stroke_width)

        if self.color_by_arc_length:
            len_to_rgb = get_rgb_gradient_function(
                self.min_arc_length,
                self.max_arc_length,
                colors=self.colors,
            )
            for line in self:
                arc_length = line.get_arc_length()
                rgb = len_to_rgb([arc_length])[0]
                color = rgb_to_color(rgb)
                line.set_color(color)
        elif self.color_by_magnitude:
            image_file = get_color_field_image_file(
                lambda p: get_norm(func(p)),
                min_value=self.min_magnitude,
                max_value=self.max_magnitude,
                colors=self.colors,
            )
            self.color_using_background_image(image_file)
Beispiel #8
0
 def __init__(self, function=None, **kwargs):
     # either get a function from __init__ or from CONFIG
     self.function = function or self.function
     VMobject.__init__(self, **kwargs)
Beispiel #9
0
 def __init__(self, *vertices, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.set_points_as_corners([*vertices, vertices[0]])
Beispiel #10
0
 def __init__(self, points, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.set_points(points)
Beispiel #11
0
 def __init__(self, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.set_points_as_corners(
         [consts.UP, consts.UP + consts.RIGHT, consts.RIGHT])
     self.set_width(self.width, about_point=consts.ORIGIN)
     self.rotate(self.angle, about_point=consts.ORIGIN)
Beispiel #12
0
 def clear(self):
     self.add_content(VMobject())
     return self
Beispiel #13
0
 def get_start(self):
     if self.has_start_tip():
         return self.start_tip.get_start()
     else:
         return VMobject.get_start(self)
Beispiel #14
0
 def __init__(self, focus_point, **kwargs):
     self.focus_point = focus_point
     # Initialize with blank mobject, while create_target
     # and create_starting_mobject handle the meat
     super().__init__(VMobject(), **kwargs)
Beispiel #15
0
 def __init__(self, **kwargs):
     VMobject.__init__(self, **kwargs)
     self.add_iris_back()
     self.add_spikes()
     self.add_pupil()
Beispiel #16
0
 def __init__(self, path_string, **kwargs):
     digest_locals(self)
     VMobject.__init__(self, **kwargs)
Beispiel #17
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()
Beispiel #18
0
 def __init__(self, start_angle=0, angle=consts.TAU / 4, **kwargs):
     self.start_angle = start_angle
     self.angle = angle
     VMobject.__init__(self, **kwargs)
Beispiel #19
0
 def __init__(self, start=consts.LEFT, end=consts.RIGHT, **kwargs):
     digest_config(self, kwargs)
     self.set_start_and_end_attrs(start, end)
     VMobject.__init__(self, **kwargs)
Beispiel #20
0
 def get_center(self):
     result = VMobject.get_center(self)
     if hasattr(self, "center_offset"):
         result -= self.center_offset
     return result