0

每当我尝试在 JES 中运行诸如此类的程序时,每当我在括号内放置任何内容时,程序都无法运行?!我究竟做错了什么!当我尝试运行程序并输入图像(pict)时,它只是说错误,全局找不到名称。高清图像(图片):

我在下面制作的这段代码也有什么问题,它们不会运行,你能否详细解释我的代码的每一部分,因为我知道要写什么,但我无法理解该怎么做。

另外,如何使用 while 语句编写函数,即使用 addLine() 从使用输入为地图上的多条路线添加路线?

def startEnvironemnt(pict):
  a = pickAFile()
  pict = makePicture(a)
  sourceH = getHeight(pict)
  sourceW = getWidth(pict)
  canvas = makeEmptyPicture(sourceW, sourceH)
  show(canvas)
  show(pict)
  explore(pict)

前 2

def chromeKey(pict)
  for x in range(0, getWidth(pict)):
    for y in range(0, getHeight(pict)):
      pix = getPixel(pict, x, y)
      if(getRed(pix) + getGreen(pix) < getBlue(pix)):
        setColor(pix, getColor(getPixel(canvas,x,y)))
  return pict

prog 3:这应该编写一个 prog 来混合两张图片,1. 混合第一张图片的前三分之一 2. 然后在中间三分之一处混合两张图片 tpgether,3. 然后显示第二张图片的最后三分之一

将源图像设置为相同大小的程序

def blendImg():
  #mark on the moon
  a = pickAFile()
  source = makePicture(a)
  #WaterFall
  b = pickAFile()
  secondImg = makePicture(a)
  sHeight = getHeight(secondImg)
  sW = getWidth(secondImg)
  canvas = makeEmptyPicture(sHeight, sW)
  #Copy of pic 1, 94columns(1/3 of image)
  sourceX=0
  for targetX in range(0,94):
    sourceY=0
    for targetY in range(0, getHeight(source)):
      color = getColor(getPixel(source,sourceX,sourceY))
      setColor(getPixel(canvas,targetX,targetY),color)
      sourceY = sourceY + 1
    sourceX = sourceY + 1
   #actual blending
    blend = getWidth(source)-94
    sourceX=0
    for targetX in range(150,getWidth(source)):
      sourceY=0
      for targetY in range(0,getHeight(secondImg)):
        sPixel = getPixel(source,sourceX+94,sourceY)
        sImgPixel = getPixel(secondImg,sourceX,sourceY)
        newRed = 0.25*getRed(sPixel)+0.25*getRed(sImgPixel)
        newGreen = 0.25*getGreen(sPixel)+0.25*getGreen(sImgPixel)
        newBlue = 0.25*getGreen(sPixel)+0.25*getGreen(sImgPixel)
        nColor = makeColor(newRed,newGreen,newBlue)
        setColor(getPixel(canvas,targetX,targetY),nColor)
        sourceY = sourceY+1
      sourceX = sourceX+1
      sourceX=blend
      for targetY in range(94+blend,94+getWidth(secondImg)):
        sourceY=0
        for targetY in range(0,getHeight(secondImg)):
          color = getColor(getPixel(secondImg,sourceX,sourceY))
          setColor(getPixel(canvas,targetX,targetY),color)
          sourceY = sourceY + 1
        sourceX = sourceX + 1
    show(canvas)
    return(canvas)
4

1 回答 1

0

通常,您会想尝试在 stackoverflow 上提出问题,以便每个问题都有一个问题。

要使第一个程序正常工作,您需要执行以下操作(不要键入>>>,这只是提示):

>>> picture = makePicture(pickAFile())
>>> startEnvironemnt(picture)

请注意,在函数的定义中,您使用pict了并且在提示符处我使用了picture. 只要您在提示符处使用相同的名称,您就可以使用任何您喜欢的非保留词。如果它告诉您 pict 未定义,请确保您pict = makePicture(pickAFile())在尝试使用它之前已使用赋值语句(如代码中某处)给它一个值。

程序 2 在第一行末尾缺少一个冒号,所以这不太可能工作。

我认为您应该编辑您的问题以将 while 循环部分拉到一个单独的问题中。

于 2014-08-07T20:23:20.957 回答