Color Variant Bindings

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).

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

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

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

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)

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

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

then, R, G, and B are

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

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.

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

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.

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.

You may be interested in using an HSV method.

2 Likes