Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import random
- def thing(val):
- val += (-4, -3, -2, -1, 1, 2, 3, 4)[random.getrandbits(3)]
- if val < 0: return 0
- if val > 255: return 255
- return val
- def neighbours(coord, w, h):
- offsets = ((-1, -1), (-1, 0), (-1, 1), (1, -1), (1, 0), (1, 1), (0, -1), (0, 1))
- for xo, yo in offsets:
- nx = coord[0] + xo
- ny = coord[1] + yo
- if nx >= 0 and nx < w and ny >= 0 and ny < h:
- yield nx, ny
- w = 720
- h = 1280
- im = Image.new('RGB', (w, h))
- save_frames = False
- done = set()
- total = w * h
- pending = set()
- pending.add((0, 0, 0, (0, 0)))
- n_iters = 0
- frame = 0
- while pending:
- if n_iters % 10000 == 0:
- print(len(done), total, frame)
- if save_frames:
- im.save(f'{frame:04d}.bmp')
- frame += 1
- r, g, b, dest = pending.pop()
- r = thing(r)
- g = thing(g)
- b = thing(b)
- im.putpixel(dest, (r, g, b))
- done.add(dest)
- n_iters += 1
- for neighbour in neighbours(dest, w, h):
- if neighbour not in done:
- pending.add((r, g, b, neighbour))
- if save_frames:
- im.save(f'{frame:04d}.bmp')
- else:
- im.save('ass.png')
Add Comment
Please, Sign In to add comment