# Color Variant Bindings

**URL:** <https://forum.inductiveautomation.com/t/color-variant-bindings/87758>\
**Category:** Ignition\
**Tags:** vision, ignition81\
**Created:** [March 22, 2024, 4:56pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758 "2024-03-22T16:56:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [March 22, 2024, 4:56pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758/1 "2024-03-22T16:56:34Z")

</div>

I have one `color` that is a parameter to a template.

I want 3 shades of this color, with the supplied shade being the lightest and one `darker()` being the `darkest`. How can I get one shade in-between `color` and `darkest`? (i.e.`avg(color,darkest)`)

I feel like `darker()` and `lighter()` would be more useful with another arg for the % between this shade and next (100% would be `darker()` 0% would be no change).

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 22, 2024, 5:03pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758/2 "2024-03-22T17:03:01Z")

</div>

~~I'm pretty sure the `toInt` expression function works on colors, as long as you're on a fairly new version.~~

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [March 22, 2024, 5:05pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758/3 "2024-03-22T17:05:16Z")

</div>

I don't think so... Trying to bind `toInt(Block.color)` gets Null

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [March 22, 2024, 5:08pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758/4 "2024-03-22T17:08:00Z")

</div>

Is there an easy way to strip the R, B, and G from the color?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 22, 2024, 5:15pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758/5 "2024-03-22T17:15:02Z")

</div>

Not via expressions, but it's easy in scripting. `java.awt.Color` is (generally) just a wrapper around an int: [Color (Java SE 17 & JDK 17)](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/Color.html)

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [March 22, 2024, 5:19pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758/6 "2024-03-22T17:19:06Z")

</div>

2 steps is not too bad. Used an intermediate `RGBA` string:

```auto
substring(toStr({Block.color}),6,len(toStr({Block.color}))-1)

```

then, R, G, and B are

```auto
split({Block.RGBA},',')[0,0]

```

```auto
split({Block.RGBA},',')[1,0]

```

```auto
split({Block.RGBA},',')[2,0]

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 22, 2024, 5:19pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758/7 "2024-03-22T17:19:29Z")

</div>

Ah, I was wrong about `toInt`. We made `toHex` work for colors to return web-ish color strings more easily. I suppose you could also `fromHex(toHex(color))` to get an int.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [March 22, 2024, 5:23pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758/8 "2024-03-22T17:23:26Z")

</div>

I think I'll just make the template the shades of gray that I want and throw a tint over it...

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [March 22, 2024, 5:33pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758/9 "2024-03-22T17:33:13Z")

</div>

Tint looked _ok_ but not great...

I ended up doing it the "longer" way

1. `color` template parameter
2. Make it `darker()` (`Color_Darkest`)
3. Extract out R, G, and B for both `color` and `Color_Darkest`
4. use `color()` to create a mid-shade color using `R` and `R_Darkest`, `G` and `G_Darkest`, and `B` and `B_Darkest`.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [March 22, 2024, 5:33pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758/10 "2024-03-22T17:33:40Z")

</div>

Oddly enough, converting back to hex and then to color doesn't work.

\*\*edit: I guess I didn't type it right the first time because it definitely works now... but doing the average of two integer-converted hex colors **does not** give you a shade in-between.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 22, 2024, 5:58pm UTC](https://forum.inductiveautomation.com/t/color-variant-bindings/87758/11 "2024-03-22T17:58:05Z")

</div>

> [@amarks](#):
>
> but doing the average of two integer-converted hex colors **does not** give you a shade in-between.

You may be interested in using an HSV method.

> [@Code review: Modifying RGB by Manipulating HSV colors](https://forum.inductiveautomation.com/t/code-review-modifying-rgb-by-manipulating-hsv-colors/58295/4):
>
> That’s fair. I would expect better performance out of a more Java-based solution, but it’s very likely not going to be enough to actually matter. For posterity, a reimplementation of your method: def mulColorV(rgbHex, factV): from com.inductiveautomation.ignition.common import TypeUtilities from java.awt import Color javaColor = TypeUtilities.getColorFromString(rgbHex) hsl = Color.RGBtoHSB(javaColor.red, javaColor.green, javaColor.blue, None) hsl[2] = max(0.0, min(hsl[2] \* factV, 1.0)) h…
