Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_mesmerize5.py
- from tkinter import *
- import time
- from PIL import Image, ImageTk
- from random import shuffle as rs, randint as ri, choice as rc
- tx = time.time
- ww = 200
- hh = 200
- root = Tk()
- root.title("Tk_mesmerize")
- root.geometry("%dx%d+-6+-2"%(ww,hh))
- canvas = Canvas(width=ww, height=hh)
- canvas.pack()
- def rgb2hex(r,g,b):
- return '#%02X%02X%02X'%(r,g,b)
- def motion(event):
- mouse_pos.append((event.x, event.y))
- root.bind('<B1-Motion>', motion)
- cols = ww
- rows = hh
- rainbow=[]
- def z(r,g,b):
- rainbow.append((r,g,b))
- r,g,b=255,0,0
- for g in range(256):
- z(r,g,b)
- for r in range(254, -1, -1):
- z(r,g,b)
- for b in range(256):
- z(r,g,b)
- for g in range(254, -1, -1):
- z(r,g,b)
- for r in range(256):
- z(r,g,b)
- for b in range(254, -1, -1):
- z(r,g,b)
- rainbow = rainbow[1:-1]+rainbow[::-1]
- max_rgb=len(rainbow)
- rgb = []
- screen = []
- xy = {}
- for j in range(0,rows):
- for i in range(0,cols):
- xy[i,j] = len(rgb)
- rgb += [(ri(0,9999))]
- if (0 < i < cols-1) and (0 < j < rows-1):
- screen += [(i,j)]
- rs(rgb)
- current = rgb[:]
- mouse_pos = []
- image = Image.new("RGB", (ww,hh))
- def draw():
- image.putdata(rgb)
- photo = ImageTk.PhotoImage(image)
- canvas.create_image(0,0,image=photo,anchor=NW)
- canvas.update()
- def sides(i,j):
- return ([i-1,j],[i+1,j],[i,j-1],[i,j+1])
- swap = 1
- L = ww*hh
- #Mainloop
- while 1:
- # rs(screen)
- for i,j in screen:
- t = xy[i,j]
- v = 0
- for x,y in sides(i,j):
- v += current[xy[x,y]]
- current[t] = (int(v/4)+50)%max_rgb
- rgb[t] = rainbow[current[t]]
- rainbow = [rainbow[-1]]+rainbow[:-1]
- draw()
Add Comment
Please, Sign In to add comment