Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_MATRIX_Digital_Rain.py
- import tkinter
- import time
- import random
- katakana = '''あ い う え お が ぎ ぐ げ ご ざ じ ず ぜ ぞ だ ぢ づ で ど な に ぬ ね の は ぷ
- ぺ ま み む め も や ゆ よ ら り る れ わ ゐ ゑ を ん ア イ ウ オ カ ガ キ グ ゲ コ サ シ ス ゼ
- ソ タ チ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ペ ホ マ ミ ム メ モ ヤ ユ ラ リ ル レ ワ ヰ ヱ ヲ ン ヴ'''.split(' ')
- chars = katakana + list('23457'*2)
- ww = 800
- hh = 600
- root=tkinter.Tk()
- root.title("Tk_MATRIX_Digital_Rain")
- root.geometry(str(ww)+"x"+str(hh)+"+-10+0")
- canvas=tkinter.Canvas(root, width=ww, height=hh, bg='#000000')
- canvas.pack()
- HEIGHTOFTEXT=18
- def rgb2hex(r,g,b):
- return '#%02X%02X%02X'%(r,g,b)
- def find_speed():
- return random.uniform(HEIGHTOFTEXT*3.0, HEIGHTOFTEXT*0.3)
- white = rgb2hex(255,255,255)
- DIMMER = [white]+[rgb2hex(0,g,max(0,160-g*15)) for g in range(10,255,10)][::-1]
- Ldim = len(DIMMER)
- across = [x for x in range(15, ww, 15)]
- random.shuffle(across)
- x = {}
- y = {}
- speed = {}
- streak = {}
- while 1:
- canvas.delete('all')
- if across:
- L = across.pop(0)
- x[L] = L
- y[L] = 0
- speed[L] = find_speed()
- streak[L] = [random.choice(chars) for dim in DIMMER]
- rain = list(x)
- for L in rain:
- x2,y0 = L,int(y[L]/HEIGHTOFTEXT*HEIGHTOFTEXT)
- for index in range(Ldim):
- if not random.randint(0,4):
- streak[L][index] = random.choice(chars)
- t = streak[L][index]
- y2 = int(y0-(index*HEIGHTOFTEXT))
- canvas.create_text(x2, y2, text=t, font='bold', fill=DIMMER[index])
- streak[L].insert(0, random.choice(chars))
- streak[L].pop()
- y[L] += speed[L]
- if y[L]-HEIGHTOFTEXT*50 > hh:
- y[L] = 0
- speed[L] = find_speed()
- '''
- wait=time.time()+0.8 ### moderate speed
- while time.time() < wait:
- canvas.update()
- '''
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement