If one knows the "weights" of red, green, and blue, one can create a color using a class like
.blaRGB {
color: rgb(128, 128, 128)
}
.blaHSL {
color: hsl(33%, 34%, 33%)
}
and use it in HTML like so:
<p class="blaRGB">BLA RGB</p>
<p class="blaHSL">BLA HSL</p>
With the values shown above, blaRGB
is dingy gray and blaHSL
is white.
But what if one wants to represent combinations of other colors, such as green, blue, orange, and gold?
Is there a way to define such colors with a notation like the following?
.CyndiLauper {
color: truecolors(24, 13, 11, 12)
}
Or with color: gbog(24, 13, 11, 12)
where the letters in gbog
stand for green, blue, orange, and gold respectively?
The intent is that with the CSS definition above, the HTML
<p class="CyndiLauper">These are your True Colors, shining through!</p>
would display the text in a weighted combination of those four colors.
I believe this is possible using some convoluted math using the RGB values of green, blue, orange, and gold, but I don't know how to proceed with that.
UPDATE
I realize that a key component to the question, which I initially omitted, would be, "What exactly do you mean by green, blue, orange, and gold"?
To answer that, according to the official "True Colors" website, and using the ColorZilla browser add-in, the RGB values for these colors are:
green = 15, 167, 73
blue = 0, 152, 215
orange = 243, 123, 38
gold = 255, 230, 101
(They actually look more like forest green, dodger blue, red-orange, and yellow to me.)
I wonder if the answer isn't just to 'mix' colors in RGB?
No, you cannot. Here is a link to W3 Css Colors definition which states at the top that only blue, red, and green can be used.
Edit: Ok, so let me clarify. Natively, this is not possible, from my understanding. However, there may be things you can do using Less and Sass that can achieve your desired result. Here is some tutorial regarding Less Color functions. Most interestingly is the part about Mixing colors:
You would need to explore this, however, as I have no experience with it.
I'm not sure dividing by 50 is the right/best thing to do, but this pretty much works:
Here's what the util looks like:
Cyndi Lauper, eat your heart out!
There are many ways to mix colors, depending on what color model you're using:
The following code snippet demonstrates two mixing methods. The leftmost column displays the four original colors. The next column shows the same colors with 0.25 opacity, resulting in translucent colors. The third column layers the translucent colors on top of one another, which is equivalent to alpha compositing.
The fourth column shows an alternative approach to mixing. Here we see the result of separately averaging the R, G, and B components of each of the four original colors.
In the demonstration above, we let the web browser do the alpha compositing for us. We can also do alpha compositing directly. Layer opacity is equivalent to the alpha channel, so we set the alpha channel of each color to the weight of the color. In other words, if the weight of a color is 25%, we set its alpha channel to 0.25.
Note that the alpha channel ranges from 0 to 1. However, our RGB components range from 0 to 255.
Suppose we are mixing these two colors:
background
with alpha channelalpha.background
foreground
with alpha channelalpha.foreground
We calculate the resulting color's alpha channel
alpha.mix
like so:To compute the R component of the RGB value
mix
, we do this:And likewise for the G component
mix.g
and the B componentmix.b
.The code snippet below is an interactive demonstration that compares alpha compositing with the simpler approach of averaging the RGB components in parallel. Run the code and play around with the sliders to see the difference between these two approaches.