2

Pretty new to programming and wasn't able to find any ways of doing this without the use of PIL etc, if I am wrong please point me in the right direction!

I need to modify the following code so that it will copy the image to TGT at a size chosen by the scale input. At this stage I have gotten it so that the picture copies onto a canvas which size is determined by the scale input but cannot workout how to make the image itself scale.

Any help is greatly appreciated.

def driver():
    pic = makePicture(pickAFile())
    repaint(pic)
    modifiedPic = scale(pic,2.0)
    repaint(modifiedPic)

def scale(srcPic,scale):
    xStart = 0
    yStart = 0
    xEnd = getWidth(srcPic)
    yEnd = getHeight(srcPic)
    width = getWidth(srcPic)
    height = getHeight(srcPic)
    tgt = makeEmptyPicture(width*int(scale),height*int(scale))

    for x in range(0,width):
        for y in range(0,height):
            pxSrc=getPixel(srcPic,x,y)
            pxTgt=getPixel(tgt,x,y)
            setColor(pxTgt,getColor(pxSrc))

    srcWidth = xEnd -xStart
    srcHeight = yEnd - yStart

    tgtWidth = int(srcWidth*scale)
    tgtHeight = int(srcHeight*scale)

    for y in range(0,tgtHeight):
        for x in range(0,tgtWidth):
            pxSrc=getPixel(srcPic,int(x/scale)+xStart,int(y/scale)+yStart)
            pxTgt=getPixel(tgt,int(xStart*scale),int(yStart*scale))
            setColor(pxTgt,getColor(pxSrc))
    return tgt
mzjn
  • 48,958
  • 13
  • 128
  • 248
Glen
  • 21
  • 3

1 Answers1

0

Try this

def scale(srcPic,scale):
  width = getWidth(srcPic)
  height = getHeight(srcPic)
  tgt = makeEmptyPicture(width*int(scale),height*int(scale))

  # get the pixel from original source
  for x in range(0, width):
    for y in range(0,height):
      pxSrc=getPixel(srcPic,x,y)

      #copy source pixel by scale amount along x and y axis
      for i in range(x * int(scale), x * int(scale) + int(scale)):
        for j in range(y * int(scale), y * int(scale) + int(scale)):
          pxTgt=getPixel(tgt,i,j)
          setColor(pxTgt,getColor(pxSrc))

  return txt
super_mario3d
  • 95
  • 1
  • 5