Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_RGB_random_scroll.py
- from tkinter import *
- from PIL import Image, ImageTk
- from math import sin, cos, radians
- import random
- ri = random.randint
- ww = 600
- hh = 600
- root = Tk()
- root.title("Tk_RGB_random_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))
- scan = [[128,128,128] for i in '.'*ww]
- def rgb2hex(r,g,b):
- return '#%02X%02X%02X'%(r,g,b)
- def draw():
- image.putdata(rgb)
- photo = ImageTk.PhotoImage(image)
- canvas.create_image(0,0,image=photo,anchor=NW)
- canvas.update()
- rgb = []
- def main():
- global rgb
- i = 0
- while len(rgb) < ww*hh:
- i = core(i)
- draw()
- while 1:
- rgb = rgb[ww:]
- i = core(i)
- draw()
- peak = 60
- def core(i):
- for j in range(ww):
- p1 = scan[j-2]
- p2 = scan[j-1]
- p3 = scan[j]
- color = []
- for k in [0,1,2]:
- t = int((p1[k]+p2[k]+p3[k])/3)
- t += ri(-peak,peak)
- if t < 0: t = 0
- elif t > 255: t = 255
- color += [t]
- scan[j-1] = tuple(color)
- rgb.extend(scan)
- return i
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement