Due: Tuesday, Nov 16, end of your lab session

Lab 8: The Third Dimension

We'll be implementing some old-fashioned three-dimensional graphics today. To view your creations, you will receive a pair of paper red-and-blue glasses in lab this afternoon (which you may keep).

Preliminaries

Set the Language level to Intermediate Student and add the image.ss HtDP teachpack.


Part 1

First, write a function

;; combine-colors: color color -> color
which takes two colors c1 and c2 and returns a new color consisting of the red component of c1 and the green and blue components of c2.

For example:

> (combine-colors (make-color 100 101 102) (make-color 200 201 202))
(make-color 100 201 202)

Next write the function combine-color-lists. It should consume two lists of colors of equal length and produce a list which is the pointwise (i.e., element-by-element) combination of the input colors.

Now write a function combine-images which consumes two images i1 and i2 of equal size and produces an image where all colors have been combined according to the meaning of combine above.

You can combine various images (e.g. rectangles, circles, triangles, text, etc.) using your combine-images function. Build several samples and include them in your submission.

[Note: Functions combine-colors, combine-color-lists and combine-images should be finished by the end of the lab session. To receive full credit, you should also get started on Part 2. Turn in all your work at the end of the lab session according to these submission instructions.]


Part 2

[Note: To receive full credit, you should have a good start on Part 2. As usual, this part will also be part of this week's homework.]

Now consider rendering an image at an apparent depth. We will represent a depth as a number, and the higher that number, the "farther away" we will consider an image to be. An image at depth 0 will appear to be on the screen, depth 1 will appear to be slightly behind the surface of the screen, and so on.

In order to be presented as a pseudo-three-dimensional picture, your program must produce two similar images, one biased for the left eye, one biased for the right; those biased images will then be combined to create a three-dimensional presentation.

Write two functions render-left-eye and render-right-eye to nudge a deep image in the appropriate direction to assist in the desired illusion of depth. The type of both functions is num image -> image. Each function should consume a depth and an image and overlay the image onto a suitably sized plain white rectangle to nudge the image to the right or left a few pixels as appropriate. Use the depth as your nudge distance.

Finally, write a function render which takes a number and an image and returns an image.

;; render : num image -> image
The function should combine the left- and right-eye biased images to produce an image that appears three-dimensional when viewed with the glasses.

You can build various three-dimensional images out of rectangles, circles, triangles, text, etc. Build several samples and include them in your submission.


A Sample


Hand in your work

To receive full credit, you should complete Part 1 (functions combine-colors, combine-color-lists and combine-images) and have made a good start on Part 2. This week's homework will include Part 2 of this lab.
Save all your files and submit all your work according to the submission instructions.


Material designed by Adam Shaw.