简体   繁体   中英

How to mirror an image on a diagonal in JES

I new to this site and to jython/python programming. So I apologise for any errors in this post. My question: I'm currently learning about mirroring images in the Jython program called JES(Jython Environment for Students), and I have a question that asks to mirror an image along the diagonal. After researching (mainly on this site) I have come up with this code to do that:

 def mirrorDiagonalBlueMotorcyle(pic):
    # Set up source picture & target picture
    height=getHeight(pic)
    width=getWidth(pic)
    newPic=makeEmptyPicture(height,width)
    # Now for the actual mirroring
    mirrorPoint=0
    for x in range(0,width,1):
      for y in range(mirrorPoint,height):
        sourcePixel=getPixel(pic,y,x)
        targetPixel=getPixel(newPic,x,y)
        color=getColor(sourcePixel)
        setColor(targetPixel,color)
        mirrorPoint+= 1
    show(newPic)
    return newPic 

However, the resulting image is not a mirror image but an image that has been whited out on the diagonal

How do I code the program to actually mirror the image not just white part of the image out?

Edit: This is the result of what PM 2Ring told me to do: Motorcycle after removing the mirrorPoint

The culprit is mirrorPoint : it ensures only the region of the source image on one side of the diagonal gets mirrored. So get rid of the mirrorPoint stuff, and change your inner loop to

for y in range(0,height):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM