c# - Color harmonies:triada, complement, analogous, monochromatic -


i need in color math. have 1 main color , need other colors of chosen harmony. need such color harmonies: triada, complement, analogous, monochromatic. need them in c#. appreciated. thanks, dima.

ok, revolves around color wheel described in link. suggest hardcoding colors in array. i'm assuming main color 1 of 12.

one helper method we're going need 1 wrap values around array, such color -1 becomes color 12 (index 11 in array):

int wrapcolor(int colorindex, int numwheelcolors) {     while(colorindex < 0)     {         colorindex += numwheelcolors;     }      colorindex = colorindex % numwheelcolors; } 

we need helper method index of color on color wheel:

int getcolorwheelindex(color color) {     if (colorwheelarray.contains(color))         return colorwheelarray.indexof(color);     else         throw new invalidargumentexception("color"); } 

now everything's in place (assuming you've got array called colorwheelarray, containing colors in order).

triada:

color[] gettriadacolors(color color) {     int colorindex = getcolorwheelindex(color, colorwheelarray.length);     return new color[]         {             color,             colorwheelarray[wrapcolor(colorindex + colorwheelarray.length / 3)],             colorwheelarray[wrapcolor(colorindex + 2 * colorwheelarray.length / 3)]         }; } 

compliment:

color getcomplimentcolor(color color) {     int colorindex = getcolorwheelindex(color, colorwheelarray.length);     return colorwheelarray[wrapcolor(colorindex + colorwheelarray.length / 2)]; } 

analogous:

color[] getanalogouscolors(color color) {     int colorindex = getcolorwheelindex(color, colorwheelarray.length);     return new color[] { color,                          colorwheelarray[wrapcolor(colorindex + 1)],                          colorwheelarray[wrapcolor(colorindex + 2)] }; } 

as don't know definition of monochromatic i'll leave you. :)


edit: if want work color i'm not 100% sure, i've got idea.

that site says wheel created picking colors in ryb color space (not rgb 1 c# uses). presumably work out how 'far' color each of colors on wheel (by converting both ryb , comparing), use functions other color(s). add on difference between color , closest wheel color (in ryb color space) each result, translating rgb store color object.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -