Ability to integrate Python or SeExpr variables into the animation timeline

In Libera.chat / #krita, ralekarts assisted me with providing
https://libera.ems.host/_matrix/media/v3/download/matrix.org/uwZCQnOxbeZnoWajCEgVktSX/GradientExpression.kra which is a quick SeExpr to reproduce an effect I was trying to make. Additionally I want to animate this in a rendered animation image/video file, by adjusting the Python $iteration variable per frame in the animation timeline.

I tried searching for related topics, but I don’t know if anything is similar, however, this seems interesting:

1 Like

Hmm… SeExpr script can be read/write from pykrita, so it almost possible. There is just little Bug in updates (also there is no signal in pykrita for current frame changed?).

Partial answer:

from random import random
from krita import Krita


def color_me_random():
    app = Krita.instance()
    doc = app.activeDocument()
    node = doc.activeNode()
    # get old SeExpr
    proprties_dct = node.filterConfig().properties()
    # overwrite SeExpr script
    proprties_dct['script'] = "\n".join([
            f"$val = voronoi(5*[$u,$v,.5],4,.6,.2);",
            f"$color = ccurve(",
            f"    $val,0,[{random()}, {random()}, {random()}],",
            f"    4,0.185,[{random()}, {random()}, {random()}],",
            f"    4,0.301,[0.651,0.447,0.165],",
            f"    4,0.462,[0.976,0.976,0.976],4);",
            f"$color"])
    # apply new SeExpr
    node.filterConfig().setProperties(proprties_dct)
    doc.refreshProjection()

# before running.
# create new document and add filllayer with SeExpr
# select layer and run following command
color_me_random()

# end result is that script gets replaced
# Bug: Document.refreshProjection() ignores changes to script???

/AkiR