Skip to content

Instantly share code, notes, and snippets.

@uwezi
Created March 19, 2023 12:52
Show Gist options
  • Save uwezi/301571ed21d093312cf5cbb3645116fb to your computer and use it in GitHub Desktop.
Save uwezi/301571ed21d093312cf5cbb3645116fb to your computer and use it in GitHub Desktop.
[Mobject grouping] Grouping squares inside a loop. #manim #square #loop #animate #vgroup
# https://discord.com/channels/581738731934056449/1021822343120687135/1021843567905353788
from manim import *
class test17(Scene):
def construct(self):
baselen = 0.5
max_n = 10
origo = 3*LEFT+3*DOWN
sq = Square(side_length=baselen)
triangle = VGroup() # create an empty group
for x in np.arange(1, max_n+1, 1):
for y in np.arange(1, x+1, 1):
triangle += sq.copy().move_to(x*baselen*RIGHT + y*baselen*UP + origo)
self.add(triangle[-1]) # retrieve latest added sq and Create
# now make a copy of the triangle
new_triangle = triangle.copy().set_color(RED)
self.play(Create(new_triangle))
self.play(Rotate(new_triangle, 720*DEGREES), run_time=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment