We’ve seen that if you increment the source picture index by 2 while incrementing the target picture index by 1 for each copied pixel, you end up with the source being scaled down onto the target. What happens if you increment the target picture index by 2 as well? What happens if you increment both by 0.5 and use int to get just the integer part?

If one increments the target picture index by 2 as well then one ends up copying over every other pixel.

```
def copyEveryOtherPixel ():
# Set up the source and target pictures
src=makePicture(pickAFile())
canvas = makeEmptyPicture(getWidth(src),getWidth(src))

sourceX = 0
for targetX in range(0, (getWidth(src)),2):
sourceY = 0
for targetY in range(0, (getHeight(src)),2):
color = getColor(getPixel(src,sourceX,sourceY))
setColor(getPixel(canvas ,targetX ,targetY), color)
sourceY = sourceY + 2
sourceX = sourceX + 2
show(canvas)
return canvas
If one increments both by 0.5, then you end up stretching out the image, while also
skipping over every other pixel.
def stretchAndCopyEveryOther ():
# Set up the source and target pictures
src=makePicture(pickAFile())
canvas = makeEmptyPicture(getWidth(src)*2,getWidth(src)*2)

sourceX = 0.0
for targetX in range(0,(getWidth(src)*2),2):
sourceY = 0.0
for targetY in range(0,(getHeight(src)*2),2):
color = getColor(getPixel(src,int(sourceX),int(sourceY)))
setColor(getPixel(canvas ,int(targetX) ,int(targetY)), color) sourceY = sourceY + 0.5
sourceX = sourceX + 0.5
show(canvas)
return canvas
```

Computer Science & Information Technology

You might also like to view...

Dragging and dropping is an effective method for moving the contents of a cell or a range of cells to others cells

Indicate whether the statement is true or false

Computer Science & Information Technology

What section of the ISO 12207 project portfolio management process involves portfolio evaluation activities?

A. 6.2.3.3.1 B. 6.2.3.3.2 C. 6.2.3.3.3 D. 6.2.3.3.4

Computer Science & Information Technology