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 (like reflections and
rotations).
copyCounterClockwise function works like Recipe #30 in your
textbook, but generalizes to take a picture as a parameter, and uses the
names targetX and targetY for the values that
will be used for the X and Y values in setColor. Copy
these functions from a web page version of this lab.
# This function works like Recipe #30 in the textbook. def copyCounterClockwise(picture): canvas = makeEmptyPicture(FILL IN THE DIMENSIONS HERE!!!!!)
# The picture on the canvas will be filled in from bottom # to top, with the left-most column of the picture copied to the bottom # row of the canvas. The upper-left corner of the picture gets copied # to the lower-left corner of the canvas. targetY = getWidth(picture) for sourceX in range(1, getWidth(picture)+1): targetX = 1 for sourceY in range(1, getHeight(picture)+1): color = getColor(getPixel(picture, sourceX, sourceY)) setColor(getPixel(canvas, targetX, targetY), color) targetX = targetX + 1 targetY = targetY - 1 # Display the results and return the canvas show(picture) show(canvas) return canvas
# This function copies a picture in a clockwise direction. def copyClockwise(picture): canvas = makeEmptyPicture(FILL IN THE DIMENSIONS HERE!!!!)
# The picture on the canvas will be filled in from the top # to the bottom, with the left-most column of the picture # copied to the top row of the canvas; the upper-left # corner of the picture gets copied to the upper-right corner # of the canvas. targetY = FILL IN AN APPROPRIATE VALUE HERE!!!! for sourceX in range(1, getWidth(picture)+1): targetX = FILL IN APPROPRIATE VALUE HERE!!!! for sourceY in range(1, getHeight(picture)+1): color = getColor(getPixel(picture, sourceX, sourceY)) setColor(getPixel(canvas, targetX, targetY), color) targetX = CHANGE targetX APPROPRIATELY HERE!!!!! targetY = CHANGE targetY APPROPRIATELY HERE
# Display the results and return the canvas show(picture) show(canvas) return canvas
copyClockwise
function, you also need to determine the
initial values of the targetX and targetY
variables, as well as how to increment or decrement them. Fill all of
these values in, and then test the functions with several different
pictures.
copySideways function that does the same
thing as the copyClockwise function,
but using only a couple of lines of code.
(You should use yourcopyCounterClockwise function from this mini-lab and the
verticalReflection
Analysis Questions: Does it matter in which order you apply theverticalReflectionandcopyCounterClockwisefunctions? Compare the behavior of thecopySidewaysfunction with the results of rotating a picture three times in the counterclockwise direction.
writePictureTo function to save one rotated 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.)