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
```
You might also like to view...
The utility that enables you to reset the Directory Services Restore Mode password is _____________
a. Ntdsutil.exe b. Restore.exe c. Addsrm.exe d. Dsrm.exe
When using the IIf function, a condition is tested, and if the condition is false, the first value of the condition is returned by the function. ____________________
Answer the following statement true (T) or false (F)
The ____________________ contains a list of the headings in a document along with the page numbers on which the headings appear.
Fill in the blank(s) with the appropriate word(s).
Placing a semicolon onto the end of the conditional one-way if statement ____.
A. causes the expression to evaluate to false B. produces a syntax error C. causes the expression to evaluate to true D. produces a null empty bodied true statement