我仍然不确定我明白你想要做什么,但我认为是这样的:你想要复制和粘贴鼻子,而不是剪切和粘贴,并且您希望粘贴的副本以与第二个示例相同的特殊方式加倍。
因此,脸部中间将有一个 10x10 的鼻子,右下角还有一个 20x20 的褪色鼻子。
首先,要复制和粘贴,您只需将像素复制到旧位置和新位置,而不是仅复制到新位置:
def copyAndPaste(picture):
height = getHeight(picture)
width = getWidth(picture)
newPicture = makeEmptyPicture(width+100, height+100)
for x in range(width):
for y in range(height):
pxl = getPixel(picture,x,y)
color = getColor(pxl)
if (x>48 and x<59) and (y>58 and y<71):
newPxl =getPixel(newPicture, x+100,y+100)
setColor(newPxl,color)
newPxl = getPixel(newPicture, x,y)
setColor(newPxl,color)
现在,要放大新粘贴的副本,只需将偏移量加倍即可。换句话说,49,59 处的第一个像素变为 149,159,但 50,60 处的像素变为 151,161,51,61 处的像素变为 153,163,依此类推。
因此,您想要的是获取距 49,59 的距离,将其加倍,加回到 49,59,然后将其移动 100,100:
if (x>48 and x<59) and (y>58 and y<71):
newPxl =getPixel(newPicture, (x-49)*2+49+100,(y-59)*2+59+100)
setColor(newPxl,color)