# Transition with gradient

**URL:** <https://forums.solar2d.com/t/transition-with-gradient/353046>\
**Category:** Advanced Graphics\
**Created:** [January 22, 2021, 11:26am UTC](https://forums.solar2d.com/t/transition-with-gradient/353046 "2021-01-22T11:26:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yirkash](https://forums.solar2d.com/user_avatar/forums.solar2d.com/yirkash/32/1237_2.png) [@Yirkash](https://forums.solar2d.com/u/Yirkash)\
**Post date:** [January 22, 2021, 11:26am UTC](https://forums.solar2d.com/t/transition-with-gradient/353046/1 "2021-01-22T11:26:25Z")

</div>

Hello. I’m trying to transition the colors of a rectangle’s fill gradient.

I have no problem with the fill color is just a single color, animating the `r`, `g` and `b` properties of the object’s `fill` property using `transition.to()`. This works perfectly.

But when the fill color is a gradient, I haven’t found a way to access the rgb values of the two colors that make up the gradient, so that I can animate them. I have tried animating `r`, `g` and `b` of `object.fill`, but to no avail. I also tried animating `r`, `g` and `b` of `object.fill.color1` or `object.fill.color2`, which did not work either.

I’ve been looking around the forum and documentation, and googled around, but haven’t found anything. While the documentation for the [Paint](https://docs.coronalabs.com/api/type/Paint/index.html) type specifies there’s `r`, `g` and `b` properties, the documentation for the [GradientPaint](https://docs.coronalabs.com/api/type/GradientPaint/index.html) type doesn’t mention any properties at all, besides those inherited from Paint.

Could someone please point me in the right direction? I would just need to know how to animate the gradient’s color, or if that’s just not possible and I should just look for another solution.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![XeduR](https://forums.solar2d.com/user_avatar/forums.solar2d.com/xedur/32/256_2.png) [@XeduR](https://forums.solar2d.com/u/XeduR)\
**Post date:** [January 22, 2021, 2:25pm UTC](https://forums.solar2d.com/t/transition-with-gradient/353046/2 "2021-01-22T14:25:21Z")

</div>

Off the top of my head, I’m not sure if it is possible to “transition the gradient fill” like that. Unless I’m mistaken, you’ll need to update fills like that separately (unless you are using shaders).

* * *

You could manoeuvre around this by creating a few functions.

First, you can add `onStart`, `onPause`, `onResume` and `onComplete` listeners to your transition call.

When you start a transition, you could add an enterFrame listener to your object that will update its fill every frame. Then, on pause or on complete, you’d simply remove the listener.

Finally, the thing that you’d actually transition would be the the rgb values that the enterFrame listener would use to create the fill.
