我需要制作一个可以复制图像但镜像的功能。我创建了镜像镜像的代码,但它不起作用,我不知道为什么,因为我跟踪了代码,它应该镜像镜像。这是代码:
def invert(picture):
width = getWidth(picture)
height = getHeight(picture)
for y in range(0, height):
for x in range(0, width):
sourcePixel = getPixel(picture, x, y)
targetPixel = getPixel(picture, width - x - 1, height - y - 1)
color = getColor(sourcePixel)
setColor(sourcePixel, getColor(targetPixel))
setColor(targetPixel, color)
show(picture)
return picture
def main():
file = pickAFile()
picture = makePicture(file)
newPicture = invert(picture)
show(newPicture)
有人可以向我解释什么是错的吗?谢谢你。