Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_grainy_rgb_scroll.py
- from tkinter import *
- from PIL import Image, ImageTk
- import math
- import random
- ww = 600
- hh = 600
- def draw():
- image.putdata(rgb)
- photo = ImageTk.PhotoImage(image)
- canvas.create_image(0,0,image=photo,anchor=NW)
- canvas.update()
- root = Tk()
- root.title("Tk_grainy_rgb_scroll")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.pack()
- image = Image.new("RGB", (ww,hh), (255,255,255))
- zzz = [i for i in range(255)]
- zzz = zzz[1:-1] + zzz[::-1]
- L = len(zzz)
- rgb = [(128,128,128)]*(ww*hh)
- ref = rgb[:ww*2]
- while 1:
- buf = []
- iii = 1
- while len(buf) < ww:
- r = g = b = 0
- for i in [iii-1,iii,iii+1]:
- r += ref[i][0]
- g += ref[i][1]
- b += ref[i][2]
- ttt = []
- for t in (r,g,b):
- t = t//3
- t += random.randint(-t//15,10)
- ttt.append(t)
- buf += [tuple(ttt)]
- iii += 1
- ref = buf * 2
- ref = [ref[-1]] + ref
- rgb.extend(buf[:ww])
- rgb = rgb[-ww*hh:]
- draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement