BlendIMG and ChromaKey() jes, explaining these functions and why my programs won't work

1.2k Views Asked by At

Whenever I try to run a program in JES such as this for example, whenever I place anything inside the parenthesis, the program won't work?! what am I doing wrong! when I try to run the program and I type in image(pict), it just says error, name not found globally. def image(pict):

also what is wrong with this code I have made below, they won't run, also can you explain each part of my code in detail, as I know what to write but I'm having trouble understanding what to do.

Also how do I write a function using a while statement, that say uses addLine() to add a route for multiple routes on a map, from using input?

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

prog 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: this is supposed to write a prog to blend two pics, 1. blend the top third of the 1st pic 2. then bled two pics tpgether in the middle third, 3. then show the last third of the second pic

program to set source images at the same size

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)
1

There are 1 best solutions below

0
On

Usually, you will want to try to ask your questions on stackoverflow so that there is one question per question.

For the first program to work, you'll need to do something like this (don't type the >>>, that's just the prompt):

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

Notice that in the definition of the function, you used pict and at the prompt I used picture. As long as you use the same name both spots at the prompt, you can use any non-reserved word you like. If it's telling you that pict is not defined, make sure you have given it a value using an assignment statement like pict = makePicture(pickAFile()) somewhere in your code before you tried to use it.

Program 2 is missing a colon at the end of the first line, so that's not likely to work.

I think you should edit your question to pull the while loop part into a separate question.