Wednesday, February 4, 2009

Chapter 6 -- Page 220 -- Listing 6.9

This listing has transposed the width and height in lines 7 and 8.  The row should iterate over the height and the column over the width.  The correct version is:
   
def double(oldimage):
oldw = oldimage.getWidth()
oldh = oldimage.getHeight()

newim = EmptyImage(oldw*2,oldh*2)

for row in range(newim.getHeight()):
for col in range(newim.getWidth()):

originalCol = col//2
originalRow = row//2
oldpixel = oldimage.getPixel(originalCol,originalRow)

newim.setPixel(col,row,oldpixel)

return newim

No comments:

Post a Comment