这是一个manim错误还是我做错了什么,以使简单的Square Fill_color失败?
这是我的代码。我希望两个正方形都会填充绿色,但只有Square1是正确的。运行Windows 10和Manim社区v0.15.2。这是一个小虫吗? Square2的评论显示了如何规避错误。
from manim import *
class MovingTriangle(Scene):
def construct(self):
square1 = Square(side_length=1,color=RED,fill_color=RED, fill_opacity=1)
square1.color = GREEN
square1.fill_color = GREEN
square1.fill_opacity = 1
square1.stroke_color = GREEN
square2 = Square(side_length=1) # if parms for any color added in this constructor then square2 would work (fill green)
square2.color = GREEN
square2.fill_color = GREEN
square2.fill_opacity = 1
square2.stroke_color = GREEN
square2.next_to(square1, RIGHT)
self.add(square1, square2)
self.wait()
Here is my code. I would expect both squares to be filled GREEN but only square1 is correct. Running Windows 10 and manim community v0.15.2. Is this a manim bug?
The comment for square2 shows how to circumvent the bug.
from manim import *
class MovingTriangle(Scene):
def construct(self):
square1 = Square(side_length=1,color=RED,fill_color=RED, fill_opacity=1)
square1.color = GREEN
square1.fill_color = GREEN
square1.fill_opacity = 1
square1.stroke_color = GREEN
square2 = Square(side_length=1) # if parms for any color added in this constructor then square2 would work (fill green)
square2.color = GREEN
square2.fill_color = GREEN
square2.fill_opacity = 1
square2.stroke_color = GREEN
square2.next_to(square1, RIGHT)
self.add(square1, square2)
self.wait()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我真的不会称其为错误,但我同意这种行为有些意外。仅通过设置
fill_color
属性来设置mobject的颜色; there is some additional stuff going on (see for example目前,最好设置构造函数中的颜色,或使用专用
set_color
,set_fill
,set_stroke
,或set_style
方法。I wouldn't really call it a bug, but I agree that the behavior is somewhat unexpected. Setting the color of a mobject just by setting the
fill_color
attribute is not supported; there is some additional stuff going on (see for example the implementation ofVMobject.set_fill
) before the color of the mobject is actually changed when rendering (most notably, the call toupdate_rgbas_array
).For now it is best to set the colors in the constructor, or to use the dedicated
set_color
,set_fill
,set_stroke
, orset_style
methods.找到了解决方案。您需要明确设置
obacity = 1.0
,因为默认情况下,大多数vmobjects都没有填充不透明度。Found a solution. You need to explicitly set
opacity = 1.0
since by default most VMobjects have no fill opacity.