Advertisement
here2share

# Tk_radial_patterns.py

Aug 27th, 2020 (edited)
1,614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. # Tk_radial_patterns.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. import random
  6.  
  7. import math
  8.  
  9. ww = 512
  10. hh = 512
  11. ww2 = ww/2
  12. hh2 = hh/2
  13. root = Tk()
  14. root.title("Tk Radial Patterns.py")
  15. root.geometry("%dx%d+0+0"%(ww,hh))
  16. canvas = Canvas(root, width=ww, height=hh)
  17. canvas.grid()
  18.  
  19. img = Image.new("RGB",(ww,hh))
  20.  
  21. ttt = range(256)
  22. ttt = [0]+ttt[:-1]+ttt[::-1]
  23. tL = len(ttt)
  24.  
  25. pix = []
  26. for y in range(hh):
  27.     for x in range(ww):
  28.         pix.append(0)
  29. 0
  30.  
  31. rrr = {}
  32. for y in range(hh):
  33.     for x in range(ww):
  34.         z = int((abs(ww2-x)**2+abs(hh2-y)**2)**0.5)
  35.         if x < ww2:
  36.             t = 0
  37.             if y > hh2:
  38.                 t = 2
  39.         else:
  40.             t = 1
  41.             if y > hh2:
  42.                 t = 3
  43.         try:
  44.             rrr[z] += [(t,x,y)]
  45.         except:
  46.             rrr[z] = [(t,x,y)]
  47. 0
  48. b = 5
  49. k = 6.4
  50. d = 10
  51. qqq = len(rrr)-1
  52. tL = len(ttt)
  53. while 1:
  54.     v = 512*b/360.0
  55.     e = 1
  56.     for z in range(qqq):
  57.         rrr[z].sort()
  58.         L = len(rrr[z])
  59.         L2 = L/2
  60.         r2 = rrr[z][L2:]
  61.         rrr[z] = rrr[z][:L2]+r2[::-1]
  62.         for p,x,y in rrr[z]:
  63.             t = (math.degrees(math.atan2(256-x,256-y))+180)*v
  64.             t = int(t+math.sin(z*k)*d+z)%tL
  65.             pix[x+y*hh] = ttt[t]   
  66.     if e:
  67.         img.putdata(pix)
  68.         imgTk = ImageTk.PhotoImage(img)
  69.         canvas.create_image(1, 1, anchor=NW, image=imgTk)
  70.         root.update()
  71.         print d,k
  72.     k += 0.003
  73.     d += 9
  74. 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement