here2share

# Tk_Animate_Tunnel.py

Mar 6th, 2021 (edited)
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. # Tk_Animate_Tunnel.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. import random
  6. import math
  7. import time
  8.  
  9. def rgb2hex(rgb):
  10.     r,g,b = [int(max(0,z)) for z in rgb]
  11.     return "#{:02x}{:02x}{:02x}".format(r,g,b)
  12.  
  13. ww = 680
  14. hh = 680
  15. root = Tk()
  16. root.title("Tk Animate Tunnel")
  17. root.geometry("%dx%d+0+0"%(ww,hh))
  18. canvas = Canvas(root, width=ww, height=hh, bg=rgb2hex((200,200,255)))
  19. canvas.grid()
  20.  
  21. def square(Ymin,Xmin,v,cl):
  22.     color = rgb2hex((cl/1.5,cl/1.5,cl))
  23.     sq = [int(z)+ww/2+10 for z in Xmin-v,Ymin-v,Xmin+v,Ymin+v]
  24.     canvas.create_rectangle(sq,fill=color,outline=color)
  25.  
  26. c = 0
  27. while 1:
  28.     canvas.delete(ALL)
  29.     delay = time.clock()+0.1
  30.    
  31.     cm = 255
  32.     a = range(370,10,-30)
  33.     d = len(a)
  34.     for n in a :
  35.         z = math.sin(c)*10
  36.         z1 = math.cos(c*0.995)*10
  37.         square(0.5-z1,0.5-d+z+z1,n*0.80, cm)
  38.         c += 1
  39.         cm -= 15
  40.        
  41.     while delay > time.clock():
  42.         0
  43.     root.update()
Add Comment
Please, Sign In to add comment