VGroup#

Qualified name: manim.mobject.types.vectorized\_mobject.VGroup

class VGroup(*vmobjects, **kwargs)[source]#

Bases: manim.mobject.types.vectorized_mobject.VMobject

A group of vectorized mobjects.

This can be used to group multiple VMobject instances together in order to scale, move, … them together.

Examples

To add VGroup, you can either use the add() method, or use the + and += operators. Similarly, you can subtract elements of a VGroup via remove() method, or - and -= operators:

>>> from manim import Triangle, Square, VGroup
>>> vg = VGroup()
>>> triangle, square = Triangle(), Square()
>>> vg.add(triangle)
VGroup(Triangle)
>>> vg + square   # a new VGroup is constructed
VGroup(Triangle, Square)
>>> vg            # not modified
VGroup(Triangle)
>>> vg += square; vg  # modifies vg
VGroup(Triangle, Square)
>>> vg.remove(triangle)
VGroup(Square)
>>> vg - square; # a new VGroup is constructed
VGroup()
>>> vg   # not modified
VGroup(Square)
>>> vg -= square; vg # modifies vg
VGroup()

Example: ArcShapeIris

../_images/ArcShapeIris-1.png
from manim import *

class ArcShapeIris(Scene):
    def construct(self):
        colors = [DARK_BROWN, BLUE_E, BLUE_D, BLUE_A, TEAL_B, GREEN_B, YELLOW_E]
        radius = [1 + rad * 0.1 for rad in range(len(colors))]

        circles_group = VGroup()

        # zip(radius, color) makes the iterator [(radius[i], color[i]) for i in range(radius)]
        circles_group.add(*[Circle(radius=rad, stroke_width=10, color=col)
                            for rad, col in zip(radius, colors)])
        self.add(circles_group)

Methods

add

Checks if all passed elements are an instance of VMobject and then add them to submobjects

Attributes

animate

Used to animate the application of any method of self.

animation_overrides

color

depth

The depth of the mobject.

fill_color

If there are multiple colors (for gradient) this returns the first one

height

The height of the mobject.

sheen_factor

stroke_color

width

The width of the mobject.

add(*vmobjects)[source]#

Checks if all passed elements are an instance of VMobject and then add them to submobjects

Parameters

vmobjects (VMobject) – List of VMobject to add

Returns

Return type

VGroup

Raises

TypeError – If one element of the list is not an instance of VMobject

Examples

Example: AddToVGroup

from manim import *

class AddToVGroup(Scene):
    def construct(self):
        circle_red = Circle(color=RED)
        circle_green = Circle(color=GREEN)
        circle_blue = Circle(color=BLUE)
        circle_red.shift(LEFT)
        circle_blue.shift(RIGHT)
        gr = VGroup(circle_red, circle_green)
        gr2 = VGroup(circle_blue) # Constructor uses add directly
        self.add(gr,gr2)
        self.wait()
        gr += gr2 # Add group to another
        self.play(
            gr.animate.shift(DOWN),
        )
        gr -= gr2 # Remove group
        self.play( # Animate groups separately
            gr.animate.shift(LEFT),
            gr2.animate.shift(UP),
        )
        self.play( #Animate groups without modification
            (gr+gr2).animate.shift(RIGHT)
        )
        self.play( # Animate group without component
            (gr-circle_red).animate.shift(RIGHT)
        )