嘿,我刚开始学习曼尼姆,但我遇到了一些奇怪的行为。如果我得到一个正方形的坐标并画出来,它们就会与正方形对齐。但是,如果我尝试移动/移动/对齐到/下一个到正方形,然后再次绘制角点,它们将不再与正方形对齐。它适用于所有方向,适用于所有比例,但奇怪的是偏移量似乎与正方形的偏移量成正比
以下是我的(提炼)代码:
def square_and_corners(square, color):
# Calculate the corners of the square
DL = square.get_left() + square.get_bottom()
DR = square.get_right() + square.get_bottom()
UL = square.get_left() + square.get_top()
UR = square.get_right() + square.get_top()
# Add corners and square
self.add(Dot(DL, color=color), Dot(DR, color=color),
Dot(UL, color=color), Dot(UR, color=color))
self.add(square)
# No moving
square1 = Square(2, color=WHITE)
square_and_corners(square1, WHITE)
# Move to RIGHT
square2 = Square(2, color=RED)
square2.move_to(RIGHT)
square_and_corners(square2, RED)
# align to the left of the central square
square3 = Square(2, color=GREEN)
square3.next_to(square1, LEFT)
square_and_corners(square3, GREEN)
解决方案代码
细节
在manim中处理一组mobject的最佳方法是将它们分组到VGroup()中通过这种方式,可以分别为组中的所有移动对象或任何需要的移动对象设置动画,减少渲染时的错误数和动画中出现的问题,减少为制作动画而编写的线条,并且在迭代中处理起来非常容易
输出
相关问题 更多 >
编程相关推荐