我必须:
编写函数mirrorClockWise(source)
以顺时针方向镜像源的每个四分之一。左上角的四分之一镜像到右上角的四分之一。右上角的四分之一镜像到右下角的四分之一。
这是我的代码,唯一的问题是右上角与应有的不同,因为它镜像的是已经镜像的左上角,而不是原始的左上角。
让我知道是否有办法解决这个问题...
def topLeft(source):
mirrorPoint = getWidth(source) / 2
width = getWidth(source)
for y in range(0,getHeight(source)/2):
for x in range(0,mirrorPoint):
leftPixel = getPixel(source,x,y)
rightPixel = getPixel(source,width - x - 1,y)
color = getColor(leftPixel)
setColor(rightPixel,color)
def topRight(source):
mirrorPoint = getHeight(source) / 2
height = getHeight(source)
for x in range(getWidth(source)/2,getWidth(source)):
for y in range(0,mirrorPoint):
topPixel = getPixel(source, x, y)
bottomPixel = getPixel(source, x, height - y - 1)
color = getColor(topPixel)
setColor(bottomPixel,color)
def bottomRight(source):
mirrorPoint = getWidth(source) / 2
width = getWidth(source)
for y in range(getHeight(source)/2,getHeight(source)):
for x in range(mirrorPoint,width):
leftPixel = getPixel(source,x,y)
rightPixel = getPixel(source,width - x - 1,y)
color = getColor(leftPixel)
setColor(rightPixel,color)
def bottomLeft(source):
mirrorPoint = getHeight(source) / 2
height = getHeight(source)
for x in range(0,getWidth(source)/2):
for y in range(mirrorPoint,height):
topPixel = getPixel(source, x, y)
bottomPixel = getPixel(source, x, height - y - 1)
color = getColor(topPixel)
setColor(bottomPixel,color)
def mirrorClockWise(source):
bottomLeft(source)
bottomRight(source)
topRight(source)
topLeft(source)