【manim】方法大全
添加多个同类项目的三种方法
背景
from manim import *
class demo(Scene):
def construct(self):
bar_width = 0.3
unit_height = 0.4
buff = 0.2
方法一
bars = VGroup(
Rectangle(height=4 * unit_height, width=bar_width),
Rectangle(height=8 * unit_height, width=bar_width),
Rectangle(height=2 * unit_height, width=bar_width),
)
bars.arrange(RIGHT, buff)
方法二
heights = [4, 8, 2]
bars = VGroup()
for l in lens:
bars.add(Rectangle(height=l * unit_height, width=bar_width))
bars.arrange(RIGHT, buff)
方法三
heights = [4, 8, 2]
bars = VGroup(*[Rectangle(height=h * unit_height, width=bar_width) for h in heights])
bars.arrange(RIGHT, buff)
效果