RGB Colors
Computers build screen colours from three channels — Red,
Green, and Blue. Each channel stores an intensity
from 0 to 255. By changing these three numbers, we can create
16,777,216 different RGB colours.
Learning Objective
- 12.6.2.1 Determine standard colors by RGB code.
Conceptual Anchor
The Three Spotlights Analogy
Imagine three spotlights aimed at the same wall: one red, one green and one blue. Each spotlight has a dimmer from 0 (off) to 255 (maximum intensity). Where the light overlaps, the colours combine. All three at maximum intensity create white light; all three switched off create black.
Interactive RGB Mixer
Move the three sliders. Predict the colour first, then compare your prediction with the preview. Notice how changing a single channel changes the final colour.
rgb(13, 148, 136)
(13, 148, 136)
#0D9488
medium
Rules & Theory
1. How an RGB value is written
An RGB colour is normally written as (R, G, B). The first number controls red, the second controls green, and the third controls blue.
1 Read the tuple (255, 128, 0)
Red is at maximum intensity (255), green is at half intensity (128), and blue is off (0). The result is orange.
2. Channel intensity
0–255
0–255
0–255
Why 0–255?
Each channel is commonly stored using 8 bits. Eight bits can represent 256 values: 0 to 255. Therefore RGB gives 256 × 256 × 256 = 16,777,216 possible colours.
3. Standard RGB Colors
Learn the primary and secondary colours first. They make it much easier to reason about unfamiliar RGB values in programming tasks.
(0, 0, 0)(255, 255, 255)(255, 0, 0)(0, 255, 0)(0, 0, 255)(255, 255, 0)(0, 255, 255)(255, 0, 255)(128, 128, 128)(255, 165, 0)| Color | RGB code | Reason |
|---|---|---|
| Black | (0, 0, 0) |
No light from any channel |
| White | (255, 255, 255) |
All channels at maximum |
| Red | (255, 0, 0) |
Only red is on |
| Green | (0, 255, 0) |
Only green is on |
| Blue | (0, 0, 255) |
Only blue is on |
| Yellow | (255, 255, 0) |
Red + Green |
| Cyan | (0, 255, 255) |
Green + Blue |
| Magenta | (255, 0, 255) |
Red + Blue |
Additive Color Mixing
RGB is an additive colour model because we add light. Combining two primary channels creates a secondary colour. Combining all three at full intensity creates white.
| Mix | Result | RGB |
|---|---|---|
| Red + Green | Yellow | (255, 255, 0) |
| Red + Blue | Magenta | (255, 0, 255) |
| Green + Blue | Cyan | (0, 255, 255) |
| Red + Green + Blue | White | (255, 255, 255) |
| No channels | Black | (0, 0, 0) |
RGB light is not the same as mixing paint
RGB uses light. Adding more RGB light makes the result brighter and can reach white. Paint and printer inks use subtractive colour mixing, so the behaviour is different.
How to Predict a Color from RGB
You do not have to memorise millions of RGB values. Compare the three channel intensities. The largest values tell you which colours dominate.
(0, 128, 128)Green + Blue, both medium, no red → a darker cyan / teal.
(255, 128, 0)Strong red + some green, no blue → orange.
(180, 180, 180)R = G = B → always a shade of gray.
Fast exam rule
If two channels are high and one is low, start from the two-colour mixing rule. If all three are equal, the result is grayscale. If all are low, the colour is dark; if all are high, it is bright.
RGB and Hexadecimal Colors
Websites often write the same RGB information in hexadecimal. A six-digit HEX colour has
three pairs: RR GG BB. Each pair represents one 0–255 channel using
hexadecimal 00 to FF.
2 Example: orange
RGB (255, 165, 0) corresponds to HEX #FFA500:
FF = 255, A5 = 165, 00 = 0.
Using RGB in Python
In Python, colours are commonly stored as tuples. The order must be
(red, green, blue).
3 Store standard colours
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
CYAN = (0, 255, 255)
MAGENTA = (255, 0, 255)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
4 Access individual channels
color = (100, 200, 50)
r = color[0] # 100
g = color[1] # 200
b = color[2] # 50
print("Red:", r)
print("Green:", g)
print("Blue:", b)
5 Generate a random RGB colour
import random
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
color = (r, g, b)
print(color)
Bridge to the next lesson: Pillow
In Pillow, the same RGB tuples are used when creating images and setting pixel colours.
For example: Image.new("RGB", (400, 300), (255, 165, 0)) creates an orange
image.
Common Pitfalls
Wrong channel order
RGB always means Red, Green, Blue. For example,
(255, 0, 0) is red, but (0, 0, 255) is blue.
Values outside 0–255
Standard 8-bit RGB channels must stay between 0 and 255.
A value such as (300, 20, -5) is invalid in normal 8-bit RGB.
Additive vs subtractive mixing
RGB is for emitted light from screens. Do not apply the same rules you use when mixing paints.
Tasks
Write the RGB tuples for red, green, blue, white, black, yellow, cyan and magenta.
Without using the mixer first, predict the colours of (0, 128, 128),
(255, 128, 0) and (160, 160, 160). Then verify your
answers using the sliders.
Use the RGB mixer to create a dark purple colour. Record the tuple you produced and explain which channels are dominant.
Compare (200, 50, 50) and (50, 200, 50). Explain why they
look different even though they contain the same three numbers.
Write a Python program that creates a list containing five RGB colour tuples of your own palette. Print each colour and its individual R, G and B channel values.
Self-Check Quiz
Q1. What RGB tuple represents pure green?
Q2. What colour is produced by (255, 255, 0)?
Q3. What happens when R = G = B?
Q4. Why can one RGB channel store 256 intensity levels?
Q5. What is the HEX form of pure blue?