Search code examples
pythonanimationcairomoviepy

Changing the fill color of an Element in Gizeh


How can I change and/or get the fill color of an Element?

I would like to do something like this

import gizeh as gz

circle = gz.circle(10, xy = (100, 100), fill = (1, 0, 0))
circle.fill = (0, 1, 0)

I tried looking at the source code, but got lost in context, transform_ctx etc. And can't find the part where the fill color is saved.


Solution

  • It seems like you cannot change the color after-the-fact.

    Calling gz.circle() eventually ends up calling shape_element: https://github.com/Zulko/gizeh/blob/d9fda97c9cc5508ecd3e6fbfa0590f763f4e2711/gizeh/gizeh.py#L378-L448

    This function has the fill argument and defines a function new_draw that draws the element. This new_draw function uses fill.

    So, basically your question is equivalent to:

    How can I make the following print 42?

    def get_func(value):
        def func():
            return value
        return func
    
    my_func = get_func(21)
    # What can I insert here to change the value to 42?
    print(my_func())
    

    I think the answer to my own question is "not possible".