php - Mixing colors(adding and subtracting colors) like in Art Class! -


I am creating a color class and I'm adding more (color, percent) to the operation; For less (color, percent) it is necessary to add and subtract colors and I have a difficult time arithmetic.

Operation - Echo color ('blue') - & gt; How can I use RGB or HSB (HSV) or hex using more ('yellow', 100%):

code> echo Color ('blue') - & gt; More ('yellow', 50%);

  • I have a very vague imagination to reduce blue + .5 * yellow = black-green

: < / P>

Operation - Echo color ('orange-yellow') -> low ('red', 50%); Orange-yellow - .5 * red = yellow


Edit:

    Strong> Thank you for your input so far. I tried to add CYM to each other in the CYM and unfortunately red (255, 0, 0) ~ = (0, 1, 1) in the CYM and after that if you add blue (0, 0, 255) to it I = (1, 1, 0) is equal to (1, 2, 1) or (1, 1, 1) which is black in the CYM

    I have a hue saturation brightness (HSB) Found the closest using. In fact it works with every color combination except the red color. I believe that it is at the beginning and end of the red color (using color degree [0, 360]).

    More of your ideas will be highly appreciated!

    Okay, after an evening with a roam around, this is the "more" method that I am really happy with.

    It uses HSB (Hu-saturation-brightness) color model, now do not ask me why I did not work the CYM. I'm a color novice. It appears as if it would work to see how the printers mix the colors. I like the HSB model, in addition, when you use the color picker, its Photoshop Is shown.

    I have added this as an answer, so let me know what you think! Thanks again!


    Any help would be great!

    Thank you, Matt

An internal solution using RGB color space To represent the colors - red, green, value. When a hex representation is required, make one with the existing values ​​and send it back.

more and less methods then just reddish in red, green or blue values.

  public function more ($ color, $ percent) {$ this- & gt; Color [$ color] + = $ this- & gt; Color [$ color] * $ percent; }  

Convert to a hex string

  public function toHex () {$ red = $ this- & gt; Color ['red']; $ Green = $ this- & gt; Color ['green']; $ Blue = $ this- & gt; color blue']; Return Sprint ("% 02x% 02x% 02X", $ red, $ green, blue); }  

Changing the string such as 'Orange-Green' contains RGB components in slightly different problems.


Comments