Mirroring an imageTake an image and mirror the left side on the right side. You want to draw the pixel in the first column in the last column, the pixel in the 2nd column in the second to last column, and so on. You'll need to introduce a variable 'mirrorCol' which tracks the right-side column as you iterate through the picture. It will start at the right-side (width of picture) and decrement by 1 each iteration: col
| row | mirrorCol | mirrorRow | | 1 | 1 | w | 1 | | 2 | 1 | w-2 | 1 | | 3 | 1 | w-3 | 1 |
... Here's our nested loop template, with pseudo-code comments of how your code should work, and ? where you'll need to fill in the blanks:
# open the pic
col=1 # deal with mirrorCol while col < ? : row = 1 while row < ? : # get the pixel from the left side # get the color from that pixel # get the pixel from the right side (using mirrorCol) # put the color from the left side into the pixel from the right side
row=row+1 col=col+1 # deal with mirror col repaint(pic)
Drawing an image within a frameYour program always loads an image which is your frame. We'll call this framepic. The user should be able to load any other picture, and your program should draw it within the boundaries of the frame. We'll call this the innerpic.
First, find the coordinates of where the innerpic should go within framepic. Use the Picture Tool to do this.
Like with the mirror program, we want to grab a pixel from somewhere and draw it somewhere else. In this case, we'll getPixel from one pic (innerpic) and draw it on another pic (framepic)
Like with the mirror program, we need to keep track of two sets of coordinates, the col,row of framepic, and the col,row of innerpic. We can call these variables:
frameCol frameRow innerCol innerRow
Where should frameCol and frameRow begin? Where should innerCol and innerRow begin?
What should your code do inside the nested loop?
Advanced
Ensuring there are no Python errors, no matter how big or small the innerpic is.
Scaling a picture down
|
|