-2

我不知道如何使用while循环扫描所有像素。

我可以用for循环来做到这一点,但是如何只使用 while 循环来做到这一点?

for x in range(0,width):
  for y in range(0,height):
    px = getPixels(pic,x,y)

___________________________

def question410():
  pic = makePicture(getMediaPath("barbara.jpg"))
  width = getWidth(pic)
  height = getHeight(pic)
  canvas = makeEmptyPicture(width,height)

  explore(pic)
  scale = 2


  x = 0
  y = 0
 while x < width:
   while y < height:
      px = getPixel(pic,x,y)
      colour = getColor(px)
      tgtPx = getPixel(canvas,x,y)
      setColor(tgtPx,colour)

      x=x+1
      y=y+1
      print x, y



  explore(canvas)
4

2 回答 2

0

您的问题似乎是x内循环而不是外循环内变量的增量。

while x < width:
  while y < height:
    # Do stuff
    y = y + 1
  x = x + 1
于 2014-10-18T11:46:18.117 回答
-3

您必须在每个循环中创建计数器变量和 ++ 或 -- 它们,直到出现中断条件。

x = 1
While (x != rangeofpixels) 
{ dostuff; x++ }
于 2014-10-16T09:21:00.273 回答