Hey all,
I'm building a color class and I'm looking to add operations more(color, percentage) & less(color, percentage). This requires being able to add and subtract colors and I'm having a hard time with the arithmetic. How do I use RGB or HSB(HSV) or HEX to do operations like:
Operation - echo color('blue')->more('yellow', 100%);
- blue + yellow = green
or
Operation - echo color('blue')->more('yellow', 50%);
- blue + .5 * yellow = dark-green
For subtracting I have a very vague notion of it:
Operation - echo color('orange-yellow')->less('red', 50%);
- orange-yellow - .5 * red = yellow
EDIT: Okay thanks for your input so far. I've tried adding CYM to each other unfortunately red (255, 0, 0) ~= (0, 1, 1) in CYM and then if you add that onto blue (0, 0, 255) ~= (1, 1, 0) it will equal (1, 2, 1) or (1, 1, 1) which is black in CYM.
I got the closest using Hue Saturation Brightness (HSB). In fact it works with every color combination except red messes up. I believe this is because red is at the beginning and end of hue (hue uses degrees [0, 360]).
Any more of your thoughts would be greatly appreciated!
EDIT 2:
Okay, so after an evening with messing around, this is a "more" method that I'm really happy with.
It uses the HSB (Hue-Saturation-Brightness) color model, Now don't ask me why I CYM didn't work. I'm a color newbie. It does seem like it would work seeing as thats how printers blend colors. I like the HSB model a lot, plus its what photoshop shows when you use the color picker.
I've added it as an answer, so let me know what you guys think! Thanks again!
Any help would be great!
Thanks, Matt