1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| from PIL import Image from tqdm import tqdm
def peano(n): if n == 0: return [[0,0]] else: in_lst = peano(n - 1) lst = in_lst.copy() px,py = lst[-1] lst.extend([px - i[0], py + 1 + i[1]] for i in in_lst) px,py = lst[-1] lst.extend([px + i[0], py + 1 + i[1]] for i in in_lst) px,py = lst[-1] lst.extend([px + 1 + i[0], py - i[1]] for i in in_lst) px,py = lst[-1] lst.extend([px - i[0], py - 1 - i[1]] for i in in_lst) px,py = lst[-1] lst.extend([px + i[0], py - 1 - i[1]] for i in in_lst) px,py = lst[-1] lst.extend([px + 1 + i[0], py + i[1]] for i in in_lst) px,py = lst[-1] lst.extend([px - i[0], py + 1 + i[1]] for i in in_lst) px,py = lst[-1] lst.extend([px + i[0], py + 1 + i[1]] for i in in_lst) return lst
order = peano(6)
img = Image.open(r"D:\\123\\4\\1.png")
width, height = img.size
block_width = width block_height = height
new_image = Image.new("RGB", (width, height))
for i, (x, y) in tqdm(enumerate(order)): new_x, new_y = i % width, i // width pixel = img.getpixel((x, height - 1 - y)) new_image.putpixel((new_x, new_y), pixel)
new_image.save("D:\\123\\4\\2.png")
|