The objectives of this lab are to become more familiar with JES, to
understand and modify more complex programs (which can include
if statements, nested loops, functions, etc.), and to do
more complicated image manipulations.
In this mini-lab, we will be writing a function that reflects an
entire image. We will be using an algorithm slightly different from
that used in the mirrorVertical and
mirrorHorizontal functions in the text (Recipes 19 and 20). Instead of using
an xoffset to move away from the line we are reflecting
about, we will create a new picture to hold the reflected image, and we
will use target and source variables to keep
track of our cooordinates in both pictures.
verticalReflection function that creates a vertical reflection of a picture. It should
take a picture as a parameter, and return a new picture of the same size reflected
vertically around the right edge. This means that the picture should appear in
the new picture as it would if you held the original up to a mirror. Here
are some hints, assuming that the dimensions of the original picture are width and height:
width and height.
width, 1) in the
new picture.height) in the original picture should show up at location (width, height) in the
new picture.width, 1) in the original picture should show up at location (1, 1) in the new picture.width, height) in the original picture should show up at location (1, height) in the new picture.width - 1, 1) in the new picture.height) in the original picture should show up at location (width - 1, height) in the new picture.
width - 2, 1) in the new picture.height) in the original picture should show up at location (width - 2, height) in the new picture.Design Questions: Focusing on rows first, for any particular pixel (x, y), what should be the y-coordinate of the corresponding pixel in the new, reflected picture? Next, let's focus on the x-coordinates: what should be the x-coordinate of the corresponding pixel in the new, reflected picture?
Analysis Question: What are the similarities and differences between themirrorVerticalfunction in Recipe 19 and your newverticalReflectionfunction?
writePictureTo function to save one reflected image, and if
necessary, the original image, in your CS107 folder.
kzoo.edu. (You may want to review
the instructions in Lab 1 if you've forgotten how
to do this.)