Lab: Transforming RGB colors

Assigned
Friday, 11 September 2026
Writeup due
Monday, 14 September 2026
Summary
We ground our understanding of the procedures for transfomring colors as well as the composition operation.
Note
This lab took students over thirty minutes. I intended it to be shorter. I may have to cut a bit.

Procedures to remember

Basic color procedures

  • (rgb r g b) - create a new RGB color.
  • (rgb r g b a) - create a new RGB color, also specifying the alpha channel.
  • (rgb-red c) - extract the red component of an rgb color.
  • (rgb-green c) - extract the green component of an rgb color.
  • (rgb-blue c) - extract the blue component of an rgb color.
  • (color-red c) - extract the red component of a color.
  • (color-green c) - extract the green component of a color.
  • (color-blue c) - extract the blue component of a color.

Transforming colors

  • (rgb-darker c) - create a darker version of c (if possible).
  • (rgb-lighter c) - create a lighter version of c (if possible).
  • (rgb-redder c) - create a redder version of c (if possible).
  • (rgb-greener c) - create a greener version of c (if possible).
  • (rgb-bluer c) - create a bluer version of c (if possible).
  • (rgb-pseudo-complement c) - get the pseudo-complement of c.
  • (rgb-complement c) - get the HSV complement of c.
  • (rgb-greyscale c) - convert c to greysacle.
  • (rgb-phaseshift c) - phase shift each component of c by 128, adding 128 to values less than 128 and subtracting 128 from values greater than or equal to 128.
  • (rgb-rotate-components c) - rotate the RGB components of c.

Combining colors

  • (rgb-add c1 c2) - Add the components of two RGB colors.
  • (rgb-subtract c1 c2) - Subtract corresponding components of c2 from c1.
  • (rgb-average c1 c2) - Average the components in c1 and c2.

Working with color names

  • (all-color-names) - list all the color names.
  • (color-name->rgb name) - convert a color name to an RGB color.
  • (find-colors name) - find all the colors that include name.

Working with images

  • (image-load filename) - load an image.
  • (pixel-map color-transformation image) - apply a color transformation to each pixel in an image.
  • `(image-save img filename) - save an image to a file. May not exist yet.

Working with procedures

  • #(expression-with-percents - Build a new procedure that takes one parameter for each percent thing in expression-with-percent.
  • (o fun1 fun2 fun3 ... funn) - Build a new procedure that applies funn then … then fun3 then fun2 then fun1 to its parameter. i* (lambda (params) body) - Build a new procedure with the given parameters and instructions.

The lab

Acknowledgements

The kitten image was downloaded from http://public-photo.net/displayimage-2485.html. Unfortunately, the site behind that URL has disappeared. Nonetheless, the kitten image lives on.

This lab was newly written for Spring 2024, based on a lab from Spring 2017. It was updated somewhat in Spring 2025. It was updated again in Fall 2026 for Scamper.