Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 1.24 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Color harmonies:triada, complement, analogous, monochromatic
  2. int WrapColor(int colorIndex, int numWheelColors)
  3. {
  4.     while(colorIndex < 0)
  5.     {
  6.         colorIndex += numWheelColors;
  7.     }
  8.  
  9.     colorIndex = colorIndex % numWheelColors;
  10. }
  11.        
  12. int GetColorWheelIndex(Color color)
  13. {
  14.     if (ColorWheelArray.Contains(color))
  15.         return ColorWheelArray.IndexOf(color);
  16.     else
  17.         throw new InvalidArgumentException("color");
  18. }
  19.        
  20. Color[] GetTriadaColors(Color color)
  21. {
  22.     int colorIndex = GetColorWheelIndex(color, ColorWheelArray.Length);
  23.     return new Color[]
  24.         {
  25.             color,
  26.             ColorWheelArray[WrapColor(colorIndex + ColorWheelArray.Length / 3)],
  27.             ColorWheelArray[WrapColor(colorIndex + 2 * ColorWheelArray.Length / 3)]
  28.         };
  29. }
  30.        
  31. Color GetComplimentColor(Color color)
  32. {
  33.     int colorIndex = GetColorWheelIndex(color, ColorWheelArray.Length);
  34.     return ColorWheelArray[WrapColor(colorIndex + ColorWheelArray.Length / 2)];
  35. }
  36.        
  37. Color[] GetAnalogousColors(Color color)
  38. {
  39.     int colorIndex = GetColorWheelIndex(color, ColorWheelArray.Length);
  40.     return new Color[] { color,
  41.                          ColorWheelArray[WrapColor(colorIndex + 1)],
  42.                          ColorWheelArray[WrapColor(colorIndex + 2)] };
  43. }