(define right (make-line (make-point 0 0) (make-point 1 1)))and then ask the
(define left (make-line (make-point 0 0) (make-point -1 1)))
(define angle (make-overlaid-image right left))
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)))The UML diagram now contains even sub-sub-steps, such as 2.1.1:
(define Y (make-overlaid-image stem angle))
(draw-on Y medium)
(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))The UML diagram of this would be
(draw-line-on (make-point 10 20) (make-point 60 70) 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
In this diagram, the name
tm has been given to the
make-transformed-medium operation, even though
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)))in place of
(draw-on base-image tm))
(draw-on base-imageThe advantage of giving the name
(make-transformed-medium turn-point medium))
tmin the diagram is that it allows us to refer to that name in step 2.
Also, note that the
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
(draw-on angle medium) (width angle)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. For example, you should be able to create a 200x300 image (by stacking and turning). Once done, you can test all your other procedures on this non-square image.
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))