from PIL import Image

filename = "SecretCard"
img = Image.open(filename+".png")
width, height = img.size
mode = img.mode

img2 = Image.new(mode, (width, height//2))
width2, height2 = img2.size

for y in range(height2):
    for x in range(width2):
        p = img.getpixel((x,height2-y-1))
        if p[3] == 0:
            img2.putpixel((x,y), img.getpixel((x,height2+y)))
        else:
            img2.putpixel((x,y), p)

img2.save(filename+"2.png")
img2.show()

img3 = Image.new(mode, (width2//2, height2))
width3, height3 = img3.size

for y in range(height3):
    for x in range(width3):
        p = img2.getpixel((width3-x-1,y))
        if p[3] == 0:
            img3.putpixel((x,y), img2.getpixel((width3+x,y)))
        else:
            img3.putpixel((x,y), p)

img3.save(filename+"3.png")
img3.show()

img4 = Image.new(mode, (width3, height3))
width4, height4 = img4.size

img4a = Image.new(mode, (width4//2, height4//2))
img4b = Image.new(mode, (width4//2, height4//2))
img4c = Image.new(mode, (width4//2, height4//2))
img4d = Image.new(mode, (width4//2, height4//2))

img4a.paste(img3.crop((0, 0, width4//2, height4//2)))
img4b.paste(img3.crop((width4//2, 0, width4, height4//2)))
img4c.paste(img3.crop((0, height4//2, width4//2, height4)))
img4d.paste(img3.crop((width4//2, height4//2, width4, height4)))

for y in range(height4//2):
    for x in range(width4//2):
        if x+y+1>=width4//2:
            p = img4a.getpixel((height4//2-y-1, width4//2-x-1))
            p_origin = img4a.getpixel((x,y))
            if p[3] != 0:
                img4a.putpixel((x,y), p)

for y in range(height4//2):
    for x in range(width4//2):
        if x<=y:
            p = img4b.getpixel((y, x))
            if p[3] != 0:
                img4b.putpixel((x,y), p)

for y in range(height4//2):
    for x in range(width4//2):
        if x>y:
            p = img4c.getpixel((y, x))
            if p[3] != 0:
                img4c.putpixel((x,y), p)

for y in range(height4//2):
    for x in range(width4//2):
        if x+y<width4//2:
            p = img4d.getpixel((height4//2-y-1, width4//2-x-1))
            if p[3] != 0:
                img4d.putpixel((x,y), p)

img4.paste(img4a.crop((0, 0, width4//2, height4//2)))
img4.paste(img4b.crop((0, 0, width4//2, height4//2)), (width4//2, 0))
img4.paste(img4c.crop((0, 0, width4//2, height4//2)), (0, height4//2))
img4.paste(img4d.crop((0, 0, width4//2, height4//2)), (width4//2, height4//2))

img4.save(filename+"4.png")
img4.show()

# for y in range(height4):
#     for x in range(width4):
#         if x <width4/2:
#             if y<height4/2:
#                 if x+y>=width4/2:
#                     p = img3.getpixel((???,???))
#                     if p[3] == 0:
#                         img4.putpixel((x,y), img3.getpixel((width3+x,y)))
#             else:
#                 pass
#         else:
#             pass


#         p = img2.getpixel((width3-x,y))
#         if p[3] == 0:
#             img3.putpixel((x,y), img2.getpixel((width3+x,y)))
#         else:
#             img3.putpixel((x,y), p)


# img4.save(filename+"4.png")
# img4.show()



