Advertisement
here2share

# Tk_flippant.py

Dec 22nd, 2021 (edited)
1,291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. # Tk_flippant.py
  2.  
  3. from Tkinter import *
  4.  
  5. import math, random, time
  6.  
  7. rndi = random.randint
  8. print
  9.  
  10. ww = 1200
  11. hh = 600
  12.  
  13. center = ww/2, hh/2
  14.  
  15. c = Canvas(width=ww, height=hh, bg='white')
  16. c.pack()
  17.  
  18. outer = [(x,0) for x in range(ww)]+[(ww,y) for y in range(hh)]+[(x,hh) for x in range(ww)[::-1]]+[(0,y) for y in range(hh)[::-1]]
  19. outerL = len(outer)-1
  20.  
  21. speed = []
  22. for z in range(-200,200):
  23.     t = int(z*0.1)
  24.     if t:
  25.         speed += [t]
  26. speed += speed[1:-1][::-1]
  27. speedL = len(speed)
  28.  
  29. i = 1
  30. t = outerL/2
  31. points = []
  32. for xy in range(0,outerL,outerL/60):
  33.     points += [(xy-((i%2)*t),rndi(0,speedL))]
  34.     i += 1
  35.  
  36. prev = 0
  37. while 1:
  38.     delay = time.time()+0.05
  39.     c.delete('all')
  40.    
  41.     polygon = []
  42.     for i,zzz in enumerate(points):
  43.         xy, sp = zzz
  44.         sp += rndi(1,3)
  45.         sp %= speedL
  46.         xy += speed[sp]
  47.         xy %= outerL
  48.  
  49.         polygon += [outer[int(xy)]]
  50.         prev = (xy+outerL/2)%outerL
  51.         points[i] = xy, sp
  52.     c.create_polygon(polygon, fill='black', outline='white', width=10)
  53.     while delay > time.time():
  54.         c.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement