TinyColor icon indicating copy to clipboard operation
TinyColor copied to clipboard

Compare similarity (test if color is red-ish)

Open Noitidart opened this issue 7 years ago • 3 comments

I am trying to test if a color is similar to red. In my app, people can choose a theme. The theme color applies to all buttons. However if the theme is "red-ish" I want to use a different color the buttons. Is there a function here I can use to determine if a color is red-ish? I tried to use readability and if value is < 1.5 like this:

const isRedish = tinycolor.readability("rgb(255,0,0)", themeColor) < 1.5;

However I don't think its working too well, like with orange "#FF5722"

Noitidart avatar Feb 24 '18 08:02 Noitidart

I'm trying to do exact;y the same thing @Noitidart - do you remember if you managed this?

richardshergold avatar Jul 24 '18 06:07 richardshergold

I needed to generate similar colors and came up with this (generates 6 similar colors):

const color = tinycolor(yourcolor);

const spinSimilar = color => {
    const spins = []
    for (let s = 1, i = 0; i < 6; i++, s += 0.25) {
        spins.push(color.spin(s).toString())
    }
    return spins
}

const similar = spinSimilar(color)

Seems to work pretty well. You can change the range (s) and the increment to get more/less similar colors.

joshuaiz avatar Mar 11 '19 00:03 joshuaiz

Thanks for sharing @joshuaiz !

Noitidart avatar Mar 11 '19 02:03 Noitidart