CS 107: Pictures and Sounds: Programming with Multimedia

Kalamazoo College

Spring 2008

Mini-Lab: Reflecting Pictures

 


Introduction

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.



Reflection

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.

  1. Write a 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:
    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 the mirrorVertical function in Recipe 19 and your new verticalReflection function?
  2. Make sure you have added appropriate comments for your function.

  3. Test your new function with various pictures. Use the writePictureTo function to save one reflected image, and if necessary, the original image, in your CS107 folder.

Print your results

  1. Print the function you created in this mini-lab and hand it in.

Post your results

  1. Create a new web page to display your reflected image, along with its original version.
  2. Copy this new web page and the images that should be on it to your personal web space on kzoo.edu. (You may want to review the instructions in Lab 1 if you've forgotten how to do this.)
  3. Include a link to your new web page from your course page. Bring up your course page in a web browser and test your link.