(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
angleto draw itself on some 100 x 100
(draw-on angle medium)The following diagram shows this operation causing two other messages to be sent: first,
rightto draw itself on
leftto draw itself on
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:
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
in turn asks
right (the first of the two constituent
images) for its
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:
(define right-b (make-turned-image left))By consulting the code on page 269 of Concrete Abstractions, draw a diagram showing how
right-bwould respond to
(width right-b)by sending another message of its own.
right-b, consider how it draws itself on
medium by making a transformed medium and asking the base
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
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
In this diagram, the name
tm has been given to the result
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
tmin 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):
right-bin place of
right. If you want extra practice, you can also redo the
Yexample with this added complication.
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:
graphics-system.scmYou should save it into your directory to get started.
Once you have defined
make-filled-triangle, you can
uncomment the definitions of
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
(show (pinwheel nova-bb))