Download the hw6Pictures folder from my download directory on panther. It should contain
PictureWorld.java
QuiltWorld.java
ExampleQuiltWorld.java
ExampleQuiltWorld.html
ExampleQuiltWorld.mcp
HW6QuiltWorld.java
HW6QuiltWorld.html
HW6QuiltWorld.mcp
KnitWorld.java
HW6KnitWorld.java
HW6KnitWorld.html
HW6KnitWorld.mcp
This assignment uses no Buggles at all. Instead, it builds complex pictures
by putting together simpler ones in various ways. The following methods
are all defined in PictureWorld.java
:
empty()
flipHorizontally (Picture p)
flipVertically (Picture p)
flipDiagonally (Picture p)
clockwise90 (Picture p)
clockwise180 (Picture p)
clockwise270 (Picture p)
beside (Picture p1, Picture p2)
above (Picture p1, Picture p2)
But you still don't have any actual pictures to work with. We could add
some methods to PictureWorld.java
to draw rectangles, triangles,
paisleys, etc. but those things might not be needed in all applications
of PictureWorld.java
. So instead, we define a
subclass of PictureWorld
, named
QuiltWorld
, which adds some simple pictures useful for
making quilts:
patch (Color c)
patch (Color.red)
returns the picture at
right.
triangles (Color llColor, urColor)
llColor
in the lower left and urColor
in the
upper right.
For example, triangles (Color.blue, Color.green)
returns
the picture at right.
Thus QuiltWorld.java
provides us with the tools to build a
wide variety of colorful quilt patterns. To actually see some of them,
we'll write another subclass named
ExampleQuiltWorld
which defines a bunch of example pictures
and adds them to a menu so you can see whichever of them you like.
ExampleQuiltWorld
and try each of the
example quilt patterns on the menu. Make up a few of your own, based on
the models in the source code. Note that for each example, you'll need
to write a new method that returns the desired picture, and
you'll need to add a line to the initializePictureChoices
method that adds a suitably labelled menu item for your picture.
After experimenting with these quilting patterns for a little while, we realize that there are certain things we want to do often, such as building a large rectangular picture from four smaller pictures, arranged 2x2.
fourPics
that does this.
fourPics
, and sketch the pictures they should produce.
fourPics
is already written for
you in QuiltWorld.java
. Note that we put
it in QuiltWorld
rather than ExampleQuiltWorld
because this is the sort of task that's likely to be useful for other
programs involving quilts.
fourPics
method.
fourPics
method by writing
one or more example methods that use it, adding them to the menu, and
running the program to see them. Do they produce the picture you
expected? Don't go on until they do.
Another common task is to build a large rectangular picture from
four copies of the same smaller picture. Write a contract and
examples for fourSame
(a method header is provided for you
in QuiltWorld.java
). Fill in the body. If you find
yourself writing code extremely similar to fourPics
,
think again and see if you can do it by using,
rather than repeating, fourPics
. Test your
fourSame
method.
fourPics
and fourSame
methods
written above will be helpful, but there are some more regularities in
the pattern that we can exploit.
For example, the quilt above can be broken down into quadrants: the
upper-right quadrant looks like the picture at right (which we call
yellowCorner
), and the other three
quadrants are simply rotations of it. So it might be helpful for us to
write a method named rotations
that takes one picture and
builds a larger picture from the four possible rotations of it.
Write a contract, examples, header, body, and test code
for the rotations
method. Now if only you had
yellowCorner
, you could just produce all the rotations of
it and you'd be done.
So, how shall we write yellowCorner
? It's made of of
four quadrants, of which the upper-left, upper-right, and lower-right
ones are identical. Let's invent a method named corner
that takes two pictures and produces a 2x2 square picture with the first
picture in the lower-left and the second picture in each of the other
three corners. Write a contract, examples, header,
body, and test code for corner
.
Similarly, write contracts, examples, bodies, and test code for
the methods patch_2x2
,
patch_4x4
, triangles_2x2
,
triangles_4x4
, and triangles_8x8
as described
in the comments in QuiltWorld.java
.
Now you can put these together to build a single method
quilt1
that draws the quilt we're interested in.
PictureWorld
can be used for more than just piecing
together squares and triangles. The famous Dutch artist M.C. Escher
invented two "knitting patterns", which we'll call A and B:
KnitWorld.java
: there are several examples in the program
already; invent some of your own.