Sub topic 3
The color wheel and hue angles
This chapter assumes you know that hue is the family a color belongs to, that screens mix red, green, and blue light, and that you can read short CSS and Python snippets. Here you will learn how the color wheel turns hue into a number you can calculate with.
From a list of hues to a circle
Hues run in a loop. Red shades into orange, yellow, green, cyan, blue, and magenta, and then magenta shades back into red. A color wheel is a circle that lays out this loop. Because the wheel is a circle, a hue can be written as an angle in degrees, from 0 to 360.
In HSL and HSV, the common anchor points are:
| Hue angle | Color name |
|---|---|
| 0 | Red |
| 60 | Yellow |
| 120 | Green |
| 180 | Cyan |
| 240 | Blue |
| 300 | Magenta |
| 360 | Red again (same as 0) |
Angle 360 and angle 0 are the same hue. This is why hue arithmetic must wrap around.
Wrapping with modulo
When you add to a hue, the result can pass 360. Subtracting from a hue can give a negative number. The fix is the modulo operation, which returns the remainder after division.
def rotate(hue, degrees):
return (hue + degrees) % 360
print(rotate(210, 180)) # 30
print(rotate(350, 30)) # 20
print(rotate(10, -30)) # 340Python's % returns a non-negative result for a positive divisor, so -20 % 360 gives 340. Some other languages do not behave this way, so check before you rely on it.
Harmonies are fixed angle offsets
A harmony is a set of hues that look good together. On the wheel, each harmony is a pattern of angle offsets from a base hue.
- Complementary: the base hue plus 180. These two hues sit directly opposite each other and give the strongest hue contrast.
- Analogous: the base hue plus and minus about 30. These neighbors feel calm and unified.
- Triadic: the base hue plus 120 and plus 240. Three evenly spaced hues give variety with balance.
def harmonies(hue):
return {
"complementary": [rotate(hue, 180)],
"analogous": [rotate(hue, -30), rotate(hue, 30)],
"triadic": [rotate(hue, 120), rotate(hue, 240)],
}
print(harmonies(210))
# {'complementary': [30], 'analogous': [180, 240], 'triadic': [330, 90]}This code runs as shown and reuses rotate from the previous block. The offsets are guides, not strict rules. Shifting an analogous pair to 20 or 40 degrees often looks just as good.
The same angles in CSS
CSS hsl() takes the hue as its first value. Changing only that number moves the color around the wheel.
:root {
--base: 210;
--accent: hsl(calc(var(--base) + 180) 80% 45%);
--neighbor: hsl(calc(var(--base) + 30) 80% 45%);
}CSS wraps hue angles itself, so values above 360 or below 0 still work.
Limits of the wheel
The wheel has two traps.
- The wheel is not perceptually even. The spacing in degrees does not match how different the colors look. Green covers a wide range of angles, while the step from red to orange looks large. Equal angle steps do not give equal visual steps.
- Hue angles depend on the model. The 0, 120, and 240 anchors for red, green, and blue hold in HSL and HSV. Traditional artist wheels place complements differently: on a red-yellow-blue wheel, the complement of red is green, but on the RGB wheel it is cyan.
Two hues at the same angle and the same saturation and lightness can also differ in perceived brightness. Yellow looks lighter than blue. A later chapter covers this.
Exercise
A base hue is 300. Using the rotate function with modulo, what are the two triadic hues, and what is the complementary hue?
Show answer
Triadic: (300 + 120) % 360 = 60 and (300 + 240) % 360 = 180. Complementary: (300 + 180) % 360 = 120.
Exercise
Why does rotate(10, -30) return 340 instead of -20?
Show answer
The modulo by 360 wraps the negative result back into the range 0 to 359, and -20 wraps to 340, the same hue on the wheel.