TwiddleLab / Code / How Computers Store Everything
Pixels and Colors
What you will learn
- A picture is a grid of pixels, each one a single colour.
- A pixel is three numbers, R, G, B, from 0 to 255: one byte each.
- Equal R, G and B make gray. 256 x 256 x 256 = 16 777 216 colours.
- Size without compression = width x height x 3 bytes.
How the lesson goes
Zoom into any photo far enough. What is it made of?
Drag the zoom all the way in.
A screen pixel is three tiny lamps: red, green and blue.
Switch them on and off. How many colours can you make?
Each lamp has a brightness from 0 to 255. Mix orange.
Drag the three bars.
Pixels and RGB.
A pixel (picture element) is one square of a picture. Resolution is how many there are: 1920 x 1080 is about 2 million.
RGB: each pixel is three numbers, red, green, blue, from 0 to 255. One byte each, so 3 bytes per pixel.
256 x 256 x 256 = 16 777 216 colours. 0, 0, 0 is black, 255, 255, 255 is white, equal numbers are grays.
Paint your own 8 x 8 sprite.
Pick a colour, then tap or drag over the squares. You'll use it twice more.
Colour match: copy each colour with three sliders.
Four targets. Lock in when you think you have it.
Which of these are true grays?
Drag each swatch into a jar. Read the numbers.
A negative filter turns every number v into 255 - v. This one has bugs.
Find the pixels of your sprite that were never flipped.
A photo is 1000 x 1000 pixels. How many bytes does it take without compression?
How big is your sprite as a file?
Drag the marker on the size scale.
Previous lesson: Letters Are Numbers · Next lesson: Sound Is a List of Numbers · Part of the course: How Computers Store Everything
Lessons are interactive and need JavaScript. Turn it on to play them.