1

I am working on a project where I need to print any image selected by the user a number of times selected by the user too.

My code is mostly working but I need to make a nested loop that will basically change the values for the Xpos and Ypos of the original image and change it to make the new picture.

def repeat(pic):
    val = requestIntegerInRange("Enter 1-10", 1, 10)
    print "The user entered :" + str(val)
    w = getWidth(pic)
    h = getHeight(pic)
    print "Height and Width of this image are:", h, w
    result = makeEmptyPicture(w, h * val)
    xpos = 0
    while(xpos < w):
        ypos = 0
        while(ypos < h):
            pixel = getPixel(pic, xpos, ypos)
            color = getColor(pixel)
            loop = 0
            while(loop <= val):
                newX = xpos
                newY = ypos + h * val
                pixel2 = getPixel(result, newX, newY)
                setColor(pixel2, color)
                loop = loop + 1
            ypos = ypos + 1
        xpos = xpos + 1 

Here val is the value selected by the user to print the image a number of times.

When I run my program with the above code it shows

The error value is: 
Inappropriate argument value (of correct type).Height and Width of the Picture are : 208 146
getPixel(picture,x,y): y (= 1456) is less than 0 or bigger than the height (= 1455)
An error occurred attempting to pass an argument to a function.
Benoît Latinier
  • 2,062
  • 2
  • 24
  • 36
vkp
  • 11
  • 3
  • You are trying to pick a pixel outside of your image `result`. (That's just to be clear about what the error tells you). Check your logic around newY computation. – Benoît Latinier Mar 20 '18 at 20:57
  • I made a loop loop=0 while(loop<=val): newX = xpos newY = ypos + h pixel2=getPixel(result,newX,newY) setColor(pixel2,color) loop=loop+1 still not able to figure out this. Im sure im making some mistake in my logic but im not able to figure it out – vkp Mar 20 '18 at 21:07
  • You should post more of your code, we a missing context here. – Benoît Latinier Mar 20 '18 at 21:08
  • def repeat(pic): val = requestIntegerInRange("Enter 1-10",1,10) print "The user entered :"+str(val) w = getWidth(pic) h = getHeight(pic) print "Height and Width of this image are:",h,w result = makeEmptyPicture(w,h*val) xpos=0 while(xpos – vkp Mar 22 '18 at 01:41

1 Answers1

0

You are doing newY = ypos + h * val where it should be newY = ypos + h * loop.

Moreover your loop on val should stop on loop < val not loop <= val. The last copy is unwanted (it's the (val + 1)th) and that's the part that makes you program fail I think.

Benoît Latinier
  • 2,062
  • 2
  • 24
  • 36