【发布时间】:2014-11-10 22:35:29
【问题描述】:
我需要创建一个函数,该函数接受矩形的尺寸,然后是所需的像素颜色。到目前为止,我的函数如下所示:
def makeRectangle(width, height, desiredPixel):
# Begin with a rectangle image with all black pixels
resultImage = EmptyImage(width, height)
# Creates the total size of the rectangle image
size = width * height
# Change the color of all pixels
for i in range(width):
resultImage.setPILPixel(i, width, desiredPixel)
return resultImage
我认为我需要使用嵌套的 for 循环,但我找不到改变所有像素颜色的方法。我现在拥有的函数会生成要更改的中间像素线。
【问题讨论】: