-1

Hue in UIColor is not the same as a standard RGB color wheel. What I mean by that is, two opposing colors on a color wheel will match (i.e., yellow and purple), but if you take two opposing colors in UIColor, for example:

Color 1: Hue 0.45
Color 2: Hue 0.95

they don't match. Is there any way to find the opposite color in the spectrum through UIColor?

jscs
  • 62,161
  • 12
  • 145
  • 186
Andrew
  • 15,489
  • 25
  • 116
  • 200
  • 3
    possible duplicate of [Hue in UIColor and standard color wheels](http://stackoverflow.com/questions/5663230/hue-in-uicolor-and-standard-color-wheels) – Caleb Jun 02 '11 at 01:47

2 Answers2

6

Colors opposite each other on a wheel not usually called "matching", they are called "complementary", as in, if you mix them together, you get white (or black if you're dealing with subtractive colors, i.e., pigments).

RGB isn't really a color "wheel" -- it's more of a cube shape. The Hue in HSB, however, is often expressed as an angle, from 0˚ to 360˚, with red at 0˚, and turquoise at 180˚. If you take a value 180˚ from whatever you start with, you get the complement: Red 0˚/turquoise 180˚, green 120˚/purple 300˚, etc. When programming, the range of hue is usually written as a fraction between 0 and 1 inclusive. In that scheme, you can do

fmod(val - 0.5, 1.0)

to get the complement.

You haven't said what result you're expecting and what result you're getting, so it's hard to be specifically helpful, but 0.95 and 0.45 are indeed complementary, and when I create UIColors with those values, I see the expected reddish and turquoise-ish hues.

The colors on a computer screen behave differently than the colors of paint, because in the first case, you are adding wavelengths of light to get a result, and in the second, you are selectively absorbing wavelengths. This may be the source of your confusion. Red plus yellow equals orange with pigments, but red plus green equals yellow with light.

jscs
  • 62,161
  • 12
  • 145
  • 186
  • I was wondering if there was a way to get a color which matches well. In a regular RGB color wheel the color on the opposite side matches, but in HSB the opposite valued color doesn't match. – Andrew Jun 02 '11 at 02:51
1

I answered a question just like this not all that long ago. The gist of it is that there are lots of different color models. Even in your question, you seem to be thinking about two different models: yellow and purple may be complimentary in a red-yellow-blue model, but not so much in a red-green-blue model.

Community
  • 1
  • 1
Caleb
  • 120,112
  • 19
  • 171
  • 259