pythonanimationmanim

How do I create a copy of something (A Mobject)? (Manim)


from manim import *

class CreateExample(Scene):
    def construct(self):
        tr_1 = Polygon([-3, -2, 0], [-3, 3, 0], [2, -2, 0])
        cc_1 = Circle().shift(2.5*LEFT+1.75*UP).scale(0.4)
        cc_2 = Circle().shift(2.5*LEFT+0.65*UP).scale(0.4)
        cc_3 = Circle().shift(1.5*LEFT+0.65*UP).scale(0.4)
        cc_4 = Circle().shift(2.5*LEFT+0.6*DOWN).scale(0.4)
        cc_5 = Circle().shift(1.5*LEFT+0.6*DOWN).scale(0.4)
        cc_6 = Circle().shift(0.2*LEFT+0.6*DOWN).scale(0.4)
        cc_7 = Circle().shift(2.5*LEFT+1.6*DOWN).scale(0.4)
        cc_8 = Circle().shift(1.5*LEFT+1.6*DOWN).scale(0.4)
        cc_9 = Circle().shift(0.2*LEFT+1.6*DOWN).scale(0.4)
        cc_10= Circle().shift(0.8*RIGHT+1.6*DOWN).scale(0.4)
        mt_1 = [[0, -1], [-1, 0]]
        gr_1 = VGroup(tr_1,cc_1,cc_2,cc_3,cc_4,cc_5,cc_6,cc_7,cc_8,cc_9,cc_10)
        self.play(Create(tr_1)) 
self.play(Create(cc_1),Create(cc_2),Create(cc_3),Create(cc_4),Create(cc_5),Create(cc_6),Create(cc_7),Create(cc_8),Create(cc_9),Create(cc_10))
        self.play(gr_1.animate.apply_matrix(mt_1), run_time=2)

Is there a way to keep an original copy of the triangle before the transformation?


Solution

  • Mobject has a copy method

    So in your example, you could just use

    tr_2 = tr_1.copy() #tr_2 is now a copy of tr_1
    

    If you want a more detailed example on its usage, you can look at this example in the official documentation which uses it to keep a reference circle.