MCS-177 Project: Implementing Computer Graphics

Due: Wednesday, December 14, at the beginning of class

Recommended preparation and schedule


For this project, you will work through section 9.4 in the text. In addition to doing most of the programming exercises in that section, you will use diagrams, introduced below, to help understand the design of the graphics system. Because diagrams are valuable not only for helping you think about the design, but also as a communication medium, you will need to include the diagrams you draw in your project report, so that you have practice communicating in this medium. You will work individually on this project.

Using Object Collaboration Diagrams

In order to understand the graphics system, it is helpful to use diagrams that show how sending a message to one object can in turn cause it to send messages to other objects. For example, suppose we do the following definitions:
    (define right (make-line (make-point 0 0) (make-point 1 1)))

(define left (make-line (make-point 0 0) (make-point -1 1)))

(define angle (make-overlaid-image right left))
and then ask the angle to draw itself on some 100 x 100 medium:
    (draw-on angle medium)
The following diagram shows this operation causing two other messages to be sent: first, angle asks right to draw itself on medium; second, angle asks left to draw itself on medium:
(diagram of right drawing on medium)

The notation used in this collaboration diagram is part of a widely used standard called UML. Each box represents an object. Their labels (such as left:line) have two parts, divided by a colon. The first part indicates the name of the specific object (left) and the second indicates the name of the general class of objects of which this is an instance (line).

We can add further detail to this diagram by showing how each line responds to the draw-on message, namely by asking the medium to draw a line:
(another diagram of right drawing on medium)

In this second diagram, there are a couple variants on the notation. Step numbers with dots in them indicate sub-steps; for example, 2.1 indicates the first sub-step of step two. The object named medium is shown with no class name after the colon, because we neither know nor care what kind of medium it is.

The same notation can also be used for simpler scenarios. For example, when we ask angle for its width, it in turn asks right (the first of the two constituent images) for its width:
(diagram of width of angle)

Continuing to a more complex example, consider doing the following:

    (define stem (make-line (make-point 0 -1) (make-point 0 0)))

(define Y (make-overlaid-image stem angle))

(draw-on Y medium)
The UML diagram now contains even sub-sub-steps, such as 2.1.1:
(diagram of Y drawing on medium)

Continuing with right-b, consider how it draws itself on medium by making a transformed medium and asking the base image, left, to draw itself on the transformed medium. To make sense of this, it would help if we first understood transformed media on their own. Suppose we do the following:

    (define example-tm (make-transformed-medium turn-point medium))

(draw-line-on (make-point 10 20) (make-point 60 70) example-tm)
The UML diagram of this would be
(diagram of draw-line on example-tm)

Make sure you understand this before proceeding. Consult Figure 9.2 on page 269; also, sketch the line from (10,20) to (60,70) and the one from (20,90) to (70,40).

Returning now to asking right-b to draw itself on medium, we can see it make a transformed medium and then ask the base image, left to draw itself on the transformed medium:
(diagram of right-b drawing on medium)

In this diagram, the name tm has been given to the result of the make-transformed-medium operation, even though this name doesn't appear in the Scheme code definition of make-turned-image. It could have, if we had written

    (let ((tm (make-transformed-medium turn-point medium)))
(draw-on base-image tm))
in place of
    (draw-on base-image 
(make-transformed-medium turn-point medium))
The advantage of giving the name tm in the diagram is that it allows us to refer to that name in step 2.

Also, note that the make-transformed-medium operation is shown as a message directed at tm, even though it is really what creates tm in the first place. (Using fancier features of UML, this could be made clearer.)

Before doing any programming for the lab, do the following diagramming exercises (as well as the one warmup given earlier):

Computer Exercises

Do exercises 9.14-9.17 (but not 9.18).

As always, be sure to thoroughly test your code. You should test procedures individually and also together. In other words, be sure that images generated by procedures you write for 9.14 through 9.17 can be passed as argument(s) to other procedures.

The following file contains the code from the book relevant to the lab:

You should save it into your directory to get started.

Once you have defined make-filled-triangle, you can uncomment the definitions of test-bb and nova-bb in the file. However, you have to put those definitions after your definition of make-filled-triangle. Once you have defined make-stacked-image, you can also try evaluating expressions like:

    (show (pinwheel nova-bb))

Project Write-Up

Your project report should simply be a collection of the UML diagrams you drew and the Scheme procedures you wrote. Nothing additional is required. As usual, to get some sense of how this project report will be graded, look at the grading sheet that we use.
Back to MCS 177 home page