Keenan's Blog

Computer Graphics From Scratch


1-3 Color Manipulation

There are a handful of operations that we will use to manipulate colors. In linear algebra colors are vectors in a 3D color space.

To modify the intensity of a color we multiply each of its color channels by a constant:

k(Red, Green, Blue) = (kRed, kGreen, kBlue)

So (32, 0, 128) is twice as bright as (16,0,64)

We can also add two colors together by adding their channels seperately:

(Red_1, Green_1, Blue_1) + (Red_2, Green_2, Blue_2) = (Red_1+Red_2, Green_1+Green_2, Blue_1+Blue_2)

So red (255,0,0) and green (0,255,0) added together gives us yellow (255,255,0)

Adding colors can also create invalid results, for instance if we doubled green (0,255,0) the result for the green value would be 510 which cannot be used in our color model. So we are going to treat any value under 0 as 0 and any value over 255 as 255

<- 1-2 Color Models 1-4 The Scene ->