What is math behind the color wheel

I want to create a pie with 12 slices, each piece of a different color.

Almost all color wheels seem to fit the same format; for example: http://www.tigercolor.com/color-lab/color-theory/color-theory-intro.htm .

But what algorithms exist for generating colors? What is the math behind RGB (theta)? Of course, this should be some kind of science, but Google does not give me any clues.

+10
math colors color-picker
Nov 20 '10 at 21:21
source share
3 answers

Take a look at http://www.easyrgb.com , it has algorithms behind many color conversions. Here RGB → HSV.

var_R = ( R / 255 ) //RGB from 0 to 255 var_G = ( G / 255 ) var_B = ( B / 255 ) var_Min = min( var_R, var_G, var_B ) //Min. value of RGB var_Max = max( var_R, var_G, var_B ) //Max. value of RGB del_Max = var_Max - var_Min //Delta RGB value V = var_Max if ( del_Max == 0 ) //This is a gray, no chroma... { H = 0 //HSV results from 0 to 1 S = 0 } else //Chromatic data... { S = del_Max / var_Max del_R = ( ( ( var_Max - var_R ) / 6 ) + ( del_Max / 2 ) ) / del_Max del_G = ( ( ( var_Max - var_G ) / 6 ) + ( del_Max / 2 ) ) / del_Max del_B = ( ( ( var_Max - var_B ) / 6 ) + ( del_Max / 2 ) ) / del_Max if ( var_R == var_Max ) H = del_B - del_G else if ( var_G == var_Max ) H = ( 1 / 3 ) + del_R - del_B else if ( var_B == var_Max ) H = ( 2 / 3 ) + del_G - del_R if ( H < 0 ) H += 1 if ( H > 1 ) H -= 1 } 
+6
Nov 20 '10 at 21:40
source share

A color wheel (such as the color set for Mac OS X, pictured below) displays hue and saturation (two of the three components from HSV Color Space ). Hue changes with angle, and saturation changes with radius. Usually there is a separate slider for the value (also known as brightness).

Mac OS X color picker

See Wikipedia on how to convert back and forth between HSV and RGB. Or maybe an API for your programming language of your choice. For example, Python has a colorsys library .

+6
Nov 20 2018-10-21
source share

If you need a color wheel, for example, the example you provided (and, like most color wheels, you will find in the colors section of the craft store), where red is the opposite of green and blue is yellow-orange, purple, opposite to yellow, and etc .., you can just do the following math to change the hue of HSL or HSV to get an obsolete hue ...

 double ToLegacyHue(double modernHue) { modernHue = ((modernHue % 360) + 360) % 360; // normalize 360 > modernHue >= 0 double ret = 0; if(modernHue < 60) { ret = modernHue * 2; } else if(modernHue < 120) { ret = modernHue + 60; } else { ret = (modernHue - 120) * 0.75 + 180; } return ret; } double FromLegacyHue(double legacyHue) { legacyHue = ((legacyHue % 360) + 360) % 360; // normalize 360 > legacyHue >= 0 double ret = 0; if(legacyHue < 120) { ret = legacyHue / 2; } else if(legacyHue < 180) { ret = legacyHue - 60; } else { ret = (legacyHue - 180) / 0.75 + 120; } return ret; } 
+1
May 16 '17 at 2:13
source share



All Articles