我的代码似乎将每一列复制到不同的位置,但我不确定将 rand.int 函数移到哪里;当它在其他任何地方时,我得到一个错误。这是我当前的代码:
def randomCollage(pic, count):
pic = makePicture(getMediaPath(pic))
canv = makePicture(getMediaPath(r"7inX95in.jpg"))
startX = 0
startY = 0
endX = getWidth(canv) - getWidth(pic)
endY = getHeight(canv) - getHeight(pic)
for count in range (0, count):
targetX = random.randint(startX, endX)
for sourceX in range(0, getWidth(pic)):
targetY = random.randint(startY, endY)
for sourceY in range(0, getHeight(pic)):
color = getColor(getPixel(pic, sourceX, sourceY))
setColor(getPixel(canv, targetX, targetY), color)
targetY = targetY + 1
targetX = targetX + 1
explore(canv)
return(canv)