Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_evolving_semi_blotches.py
- from tkinter import Tk, Canvas
- from PIL import Image, ImageTk
- import random
- ww, hh = 600, 600
- root = Tk()
- root.title("# tk_evolving_semi_blotches.py")
- ww0, hh0 = ww // 3, hh // 3
- canvas = Canvas(root, width=ww, height=hh)
- canvas.pack()
- while True:
- feed = 0.000001
- grid = [[random.randint(0, 255) for _ in range(ww0)] for _ in range(hh0)]
- new_grid = [[0 for _ in range(ww0)] for _ in range(hh0)]
- stop = 0
- while True:
- pil_img = Image.new('L', (ww0, hh0), 'white')
- pixels = pil_img.load()
- for i in range(1, hh0 - 1):
- for j in range(1, ww0 - 1):
- total = -(grid[i-1][j-1] + grid[i-1][j] + grid[i-1][j+1] + grid[i][j-1] + grid[i][j+1] + grid[i+1][j-1] + grid[i+1][j] + grid[i+1][j+1] + feed) / 50
- new_grid[i][j] = grid[i][j] + total
- try:
- pixels[i, j] = int(new_grid[i][j])
- except:
- stop = 1
- if stop:
- break
- else:
- grid = new_grid[:]
- pil_img = pil_img.resize((ww, hh), Image.BICUBIC)
- tk_img = ImageTk.PhotoImage(pil_img)
- canvas.create_image(0, 0, anchor='nw', image=tk_img)
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement