This lab assignment will have you write at least two functions in jython that will create a new image that will be a 90 degree rotation in the clockwise direction of another image. This lab is to focus on the use of the return statement in JES and having a function do one and only one thing.
In the ACCC Labs that have JES, it can be found by:
def rotate90counterclockwise():
# Set up the source and target pictures
file = pickAFile()
pict = makePicture(file)
wid = getWidth (pict)
hgt = getHeight (pict)
canvas = makeEmptyPicture(hgt, wid)
# Now, do the actual copying--swap X & Y (correctly)!
targetX = 1
for sourceX in range(1,getWidth(pict)):
targetY = 1
for sourceY in range(1,getHeight(pict)):
color = getColor(getPixel(pict,sourceX,sourceY))
setColor(getPixel(canvas, targetY, wid - targetX), color)
targetY = targetY + 1
targetX = targetX + 1
show(pict)
show(canvas)
return canvas
|
To do the rotation we need to figure out the corresponding positions of the pixels in the original image and the rotated image. During lecture for the counter-clockwise rotation, we determined that:
| a | b | c | d | e |
| f | g | h | i | j |
| k | l | m | n | o |
| k | f | a |
| l | g | b |
| m | h | c |
| n | i | d |
| o | j | e |
| pixel | Original X | Original Y | Rotated X | Rotated Y |
|---|---|---|---|---|
| a | ||||
| b | ||||
| c | ||||
| d | ||||
| e | ||||
| f | ||||
| g | ||||
| h | ||||
| i | ||||
| ... | ||||
| o |
Create a file using JES that will: