# Class 05: RGB Colors

Back to Raster Graphics. On to Transforming Colors.

This outline is also available in PDF.

Held: Thursday, 6 September 2007

## A problem: Representing colors

• CS is the study of data and algorithms.
• When working with data, we have to think about how to represent it for the computer.
• We often try to represent data in terms of simpler kinds of data.
• Numbers are one simple kind of data, but there are others.
• In addition, we need to think about what we might do with the data, and ways in which the representation affects what we might do.

## The RGB Representation

• RGB is one of the simplest representations.
• We divide a color up into three basic components: Red, Green, and Blue.
• We assign an "amount" of each color to use.
• In some variants of RGB, the "amount" is a real number between 0 and 1.
• More typically, the "amount" is an integer between 0 and 255.
• RGB colors correspond well to the traditional technology for making colors on a raster screen: There are three color beams, and RGB tells each beam how much color to provide.
• We use the numbers 0..255 because these numbers are easy to represent in binary (the underlying way in which the computer represents everything).

## An Application: Complementary Colors

• One way to work with colors is to build new colors from old by thinking about interesting combinations.
• A standard way to compute a new color is to compute the complement of the old color.
• Traditionaly complements are described in terms of a different representation.
• In the abstract, two colors are complementary if they add to grey.
• Of course, that means we need to figure out what it means to add colors.
• In RGB, adding makes some sense: You add the individual components, capping each at 255.

Related Pages:

Notes:

• Remember: Everything I hand out in class (more or less) is available online through the course Web site.
• Make sure that it's clear when you're asking a question and when you're submitting a solution. "HW3" can mean either.
• We'll spend a few minutes discussing what I intend for assignment 3.
• My laptop died, so I am even further behind on everything. I apologize.

Overview:

• Problem: representing colors.
• The RGB representation.
• Complementary colors.

Summary: Today we explore one simple representation of colors, the representation called RGB. We also explore some techniques for working with RGB colors.

Back to Raster Graphics. On to Transforming Colors.

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Mon Dec 3 09:55:55 2007.
The source to the document was last modified on Wed Sep 5 15:11:20 2007.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2007F/Outlines/outline.05.html`.

You may wish to validate this document's HTML ; ;

Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright © 2007 Janet Davis, Matthew Kluber, and Samuel A. Rebelsky. (Selected materials copyright by John David Stone and Henry Walker and used by permission.) This material is based upon work partially supported by the National Science Foundation under Grant No. CCLI-0633090. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation. This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit `http://creativecommons.org/licenses/by-nc/2.5/` or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.