JES image duplicating

440 Views Asked by At

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

There are 1 best solutions below

0
Benoît Latinier On

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.