Reputation: 5078
In additive color mixing primary colors are Red, Green and Blue (RGB).
Red = #ff0000
Green = #00ff00
Blue = #0000ff
Combining Red (#ff0000
) and Green (#00ff00
) makes Yellow (#ffff00
)
Is there some formula to calulate the hex code of a color resulting from the combination of two others ?
Something like #ff0000 + #00ff00
when applied to such a formula gives #ffff00
Upvotes: 1
Views: 7660
Reputation: 42440
You can add two HEX string like this in PHP:
$red = "FF0000";
$green = "00FF00";
$yellow = dechex(hexdec($red) + hexdec($green));
echo $yellow;
What that snippet is basically doing is converting the hex strings to numbers, adding them together, and then converting the sum back to a hex string.
Reference Links:
Upvotes: 7