RGB Colors
Computers represent colors using the RGB model — three channels
(Red, Green, Blue) each ranging from
0 to 255. Mixing these channels at different intensities creates over
16 million possible colors.
Learning Objectives
- 12.6.2.1 Determine standard colors by RGB code
Conceptual Anchor
The Spotlight Analogy
Imagine three spotlights — Red, Green, Blue — shining on a white wall. Each has a dimmer (0 = off, 255 = full brightness). Overlap all at full = white. All off = black. Different combinations = different colors.
Rules & Theory
Standard RGB Colors
| Color | RGB Code | Tuple in Python |
|---|---|---|
| Black | (0, 0, 0) | (0, 0, 0) |
| White | (255, 255, 255) | (255, 255, 255) |
| Red | (255, 0, 0) | (255, 0, 0) |
| Green | (0, 255, 0) | (0, 255, 0) |
| Blue | (0, 0, 255) | (0, 0, 255) |
| Yellow | (255, 255, 0) | (255, 255, 0) |
| Cyan | (0, 255, 255) | (0, 255, 255) |
| Magenta | (255, 0, 255) | (255, 0, 255) |
| Gray | (128, 128, 128) | (128, 128, 128) |
| Orange | (255, 165, 0) | (255, 165, 0) |
Color Mixing Rules
| Mix | Result | Why |
|---|---|---|
| Red + Green | Yellow | (255, 255, 0) |
| Red + Blue | Magenta | (255, 0, 255) |
| Green + Blue | Cyan | (0, 255, 255) |
| R + G + B (all max) | White | (255, 255, 255) |
| R + G + B (all zero) | Black | (0, 0, 0) |
| Equal R = G = B | Shade of gray | (128,128,128) = mid gray |
Using RGB in Python
# Define colors as tuples
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
YELLOW = (255, 255, 0)
ORANGE = (255, 165, 0)
# Access individual channels
color = (100, 200, 50)
r = color[0] # 100
g = color[1] # 200
b = color[2] # 50
# Total possible colors: 256 × 256 × 256 = 16,777,216Hex Color Codes
RGB can also be written in hexadecimal: #FF0000 = Red, #00FF00 = Green,
#0000FF = Blue. Each pair of hex digits = one channel (00–FF = 0–255).
Common Pitfalls
Additive vs Subtractive
RGB is additive (light-based): mixing all = white. This is the opposite of paint mixing (subtractive: mixing all = brown/black). Don't confuse the two!
Tasks
Write the RGB tuple for: red, green, blue, white, black, yellow.
What color does (0, 128, 128) produce? What about (255, 128, 0)?
Write a Python program that generates a random RGB color and prints its tuple.
Self-Check Quiz
Q1: What RGB tuple represents pure green?
Q2: What happens when R = G = B?
Q3: How many total colors can RGB represent?