【发布时间】:2013-06-16 00:33:02
【问题描述】:
我需要创建一个可以复制图像的函数,但是是镜像的。我创建了镜像镜像的代码,但它不起作用,我不知道为什么,因为我跟踪了代码,它应该镜像镜像。代码如下:
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)
有人可以向我解释什么是错的吗?谢谢。
【问题讨论】:
-
show(picture)和return picture应该缩进 -
请将您的代码块更新为
mirror;-) 您在本地文件中的内容... -
@boazdoz 当我这样做时,它会给我一个错误,试图将参数传递给函数。
-
@Golgauth 我不知道你的意思......我正在学习的这门课程是为初学者准备的 jython,所以如果这就是你所指的,我还没有被介绍过任何 python API .
-
不,但要修复问题正文中的缩进,这样我们就不会与不良缩进混淆(点击底部的
edit链接)
标签: python jython flip mirror jes