TinyColor
TinyColor copied to clipboard
Compare similarity (test if color is red-ish)
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"
I'm trying to do exact;y the same thing @Noitidart - do you remember if you managed this?
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.
Thanks for sharing @joshuaiz !