Manim: set_color(COLOR) (and some other methods mostly used for manipulating the size, position etc. of objects on canvas) dont change the attributes associated with the object.

Created on 7 Aug 2020  路  6Comments  路  Source: ManimCommunity/manim

I don't know if this is intentional but the setting methods especially those used for manipulating the position/color of objects on manim canvas don't actually change these attributes. For example, here I am trying to change the color of the TextMobject using set_color() but it is not changing the color property associated with the object although its appearance on the canvas has been changed to the desired color.

class Testing(Scene):
    def construct(self):
        some_text = TextMobject("This is some text")
        print("Color of the variable before applying set_color(): ",some_text.color)
        self.play(Write(some_text))
        self.wait()
        self.remove(some_text)
        some_text.set_color(GREEN_D)
        print("Color of the variable after applying set_color(): ",some_text.color)
        self.play(ShowCreation(some_text))
        self.wait()

Here is the output:
Testing

image

bug good first issue help wanted

All 6 comments

UPDATE
Upon further investigation, the changed color of the object can be retrieved using object.get_color() (Other get methods work fine too). However, the color property of the object still remains unchanged. To fix this, the setters should modify the properties of the object too. I made a small change to the set_color() method by adding self.color = color and now it works just as intended.

class Testing(Scene):
    def construct(self):
        some_text = TextMobject("This is some text")
        # print("Color of the variable before applying set_color(): ",some_text.color)
        self.play(Write(some_text))
        self.wait()
        self.remove(some_text)
        some_text.set_color(GREEN_D)
        print("Color of the variable using variable.get_color() : ",\
            some_text.get_color())
        print("Color of the variable using variable.color : ",\
            some_text.color)
        self.play(ShowCreation(some_text))
        self.wait()

Print statement's output before making the change to set_color(COLOR)
image
Print statement's output after making the change to set_color(COLOR)
image

self.color = color is already there though? What did you change exactly?

https://github.com/ManimCommunity/manim/blob/70c0d53a01ee6cd1da9a74c0338ed404f67b9123/manim/mobject/mobject.py#L579-L591

The vectorized M object class has its own set_color(COLOR) method defined where the COLOR passed is not set to the color attribute of the object. Looking at the method resolution order, TextMobject looks for the method set_color(COLOR) in VMobject.

https://github.com/ManimCommunity/manim/blob/70c0d53a01ee6cd1da9a74c0338ed404f67b9123/manim/mobject/types/vectorized_mobject.py#L227-L230

image

@Ammar34 would you be interested in opening a PR for this? :)

@Ammar34 would you be interested in opening a PR for this? :)

Yes sir. I was a little busy for the past two weeks. I will PR tomorrow if that is okay!

For the record, I strongly suspect that this issue is one of the big causes of the SVG rendering bugs

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kolibril13 picture kolibril13  路  5Comments

naveen521kk picture naveen521kk  路  5Comments

naveen521kk picture naveen521kk  路  4Comments

qo4on picture qo4on  路  6Comments

huguesdevimeux picture huguesdevimeux  路  6Comments