Пример #1
0
    def add_vector(self, vector, color=YELLOW, animate=True, **kwargs):
        """
        Returns the Vector after adding it to the Plane.

        Parameters
        ----------
        vector Union(Arrow,list,tuple,np.ndarray)
            It can be a pre-made graphical vector, or the
            coordinates of one.
        
        color (str)
            The string of the hex color of the vector.
            This is only taken into consideration if
            'vector' is not an Arrow. Defaults to YELLOW.
        
        animate (bool=True)
            Whether or not to animate the addition of the vector
            by using GrowArrow
        
        **kwargs
            Any valid keyword argument of Arrow.
            These are only considered if vector is not
            an Arrow.
        
        Returns
        -------
        Arrow
            The arrow representing the vector.
        """
        if not isinstance(vector, Arrow):
            vector = Vector(vector, color=color, **kwargs)
        if animate:
            self.play(GrowArrow(vector))
        self.add(vector)
        return vector
Пример #2
0
 def add_vector(self, vector, color=YELLOW, animate=True, **kwargs):
     if not isinstance(vector, Arrow):
         vector = Vector(vector, color=color, **kwargs)
     if animate:
         self.play(GrowArrow(vector))
     self.add(vector)
     return vector
Пример #3
0
    def construct(self):
        circle = Circle(color=PURPLE_A)

        square = Square(fill_color=GOLD_B, fill_opacity=1, color=GOLD_A)
        square.move_to(UP + LEFT)

        circle.surround(square)

        rectangle = Rectangle(height=2, width=3)

        ellipse = Ellipse(width=3, height=1, color=RED)
        ellipse.shift(2 * DOWN + 2 * RIGHT)

        pointer = CurvedArrow(2 * RIGHT, 5 * RIGHT, color=MAROON_C)

        arrow = Arrow(LEFT, UP)
        arrow.next_to(circle, DOWN + LEFT)

        rectangle.next_to(arrow, DOWN + LEFT)

        circle2 = Circle()
        circle2.surround(rectangle, buffer_factor=1)

        ring = Annulus(inner_radius=.5, outer_radius=1, color=BLUE)
        ring.next_to(ellipse, RIGHT)

        self.add(pointer)
        self.add(circle2)
        self.play(FadeIn(square))
        self.play(Rotating(square), FadeIn(circle))
        self.play(GrowArrow(arrow))
        self.play(GrowFromCenter(rectangle), GrowFromCenter(ellipse),
                  GrowFromCenter(ring))

        self.wait()