Search code examples
manim

Is it a Manim bug or am I doing something wrong such that simple square fill_color fails?


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()

Solution

  • 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.