这是一个manim错误还是我做错了什么,以使简单的Square Fill_color失败?

发布于 2025-02-08 09:05:33 字数 721 浏览 1 评论 0原文

这是我的代码。我希望两个正方形都会填充绿色,但只有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

踏月而来 2025-02-15 09:05:33

我真的不会称其为错误,但我同意这种行为有些意外。仅通过设置fill_color属性来设置mobject的颜色; there is some additional stuff going on (see for example

目前,最好设置构造函数中的颜色,或使用专用set_colorset_fillset_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 of VMobject.set_fill) before the color of the mobject is actually changed when rendering (most notably, the call to update_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, or set_style methods.

水晶透心 2025-02-15 09:05:33

找到了解决方案。您需要明确设置obacity = 1.0,因为默认情况下,大多数vmobjects都没有填充不透明度。

Found a solution. You need to explicitly set opacity = 1.0 since by default most VMobjects have no fill opacity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文