I'm writing a code in Jython, that will copy part of one picture into an empty picture, but I want it to copy (let's say) 10 pixels less with each next row. I don't think I make sense, let me explain with an example. A picture 100 pixels by 100 pixels, the program will copy the first row (100pixels) of pixels into the new picture, but for second row of pixels I want it to copy only 90 pixels, then for the third row 80 pixels, and so on.
Here I have a code that will copy part of a picture, but it copies a square. So what should I add to make it do what I want. I'm guessing I'm supposed to do something with the for x in range
but I don't know what.
def copyPic():
file=pickAFile()
oldPic=makePicture(file)
newPic=makeEmptyPicture(getWidth(oldPic),getHeight(oldPic))
xstart=getWidth(oldPic)/2
ystart=getHeight(oldPic)/2
for y in range(ystart,getHeight(oldPic)):
for x in range(xstart, (getWidth(oldPic))):
oldPixel=getPixel(oldPic,x,y)
colour=getColor(oldPixel)
newPixel=getPixel(newPic,x,y)
setColor(newPixel,colour)
explore(newPic)
One easy way to confuse a QR scanner is to replace the three positioning squares of a code with random cells. This has been done to
image3.png
, which is in minimal form. Your functionaddSquares(smallPic)
will add the three positioning squares and the white cells separating them from the active cells. ThenfixCodes()
will expand the resulting image and save it.Your code definitely looks like it will copy the bottom right 1/4 of the image... to make a triangle-shaped piece (or just a piece that has an angle if I understand your question properly) of that section you need to reduce the X maximum value each time through... something like:
Your code I think will take an image like this:
and give this:
because your X loop is always the same length
By reducing x each time as shown, you should get something like this:
This is not very well coded, and I could rewrite the whole thing... but if you are just learning python then at least the modifications I made to your code should work well with what you already have, and should be easy to follow. I hope that it helps, and feel free to ask for clarification if you need it.
Cheers
PS: I see you asked this twice - you shouldn't ask the same question twice since it splits the answers, and makes it harder for people trying to find answers like this later on...