Animating a gradient

Yeah, it get’s a little messy. OK, a lot messy, but it can be done. I added three extra Properties to a rectangle, Color1, Color2, and Style. This way you can pick both colors of the gradient via scripting.

if event.propertyName=="Color1": from java.awt import Color from java.awt import GradientPaint o=event.source x1=o.relX y1=o.relY Color1=o.Color1 x2=x1+o.relWidth y2=y1 Color2=o.Color2 o.setFillPaint(GradientPaint(x1,y1,Color1,x2,y2,Color2,1))

When changing the gradient this way, the Fill Paint type becomes unknown, so you have to change it to something it recognizes before yo can do anything further to it. Like copy/paste, or adjust your styles:

Perhaps someone else can chime in and tell me what I’m missing… :scratch:

Here’s a window to look at.
AnimatedGradient_2014-11-25_0850.proj (6.97 KB)

1 Like