Advertisement
cooked_marshmello

# Tk_radial_gradients_spin2.py

Aug 27th, 2020
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. # Tk_radial_gradients_spin.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 Gradients Spin.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.  
  49. b = 5
  50. qqq = len(rrr)-1
  51. spiral = 0
  52. while 1:
  53. v = 512*b/360.0
  54. for z in range(qqq):
  55. rrr[z].sort()
  56. L = len(rrr[z])
  57. L2 = L/2
  58. r2 = rrr[z][L2:]
  59. rrr[z] = rrr[z][:L2]+r2[::-1]
  60. spiral += 1.2
  61. for p,x,y in rrr[z]:
  62. p = (math.degrees(math.atan2(256-x,256-y))+180)*v
  63. pix[x+y*hh] = ttt[int(p+spiral)%tL]
  64. print b
  65. img.putdata(pix)
  66. imgTk = ImageTk.PhotoImage(img)
  67. canvas.create_image(1, 1, anchor=NW, image=imgTk)
  68. root.update()
  69. 0
  70. RAW Paste Data
  71. # Tk_radial_gradients_spin.py
  72.  
  73. from Tkinter import *
  74. from PIL import Image, ImageTk
  75. import random
  76.  
  77. import math
  78.  
  79. ww = 512
  80. hh = 512
  81. ww2 = ww/2
  82. hh2 = hh/2
  83. root = Tk()
  84. root.title("Tk Radial Gradients Spin.py")
  85. root.geometry("%dx%d+0+0"%(ww,hh))
  86. canvas = Canvas(root, width=ww, height=hh)
  87. canvas.grid()
  88.  
  89. img = Image.new("RGB",(ww,hh))
  90.  
  91. ttt = range(256)
  92. ttt = [0]+ttt[:-1]+ttt[::-1]
  93. tL = len(ttt)
  94.  
  95. pix = []
  96. for y in range(hh):
  97. for x in range(ww):
  98. pix.append(0)
  99. 0
  100.  
  101. rrr = {}
  102. for y in range(hh):
  103. for x in range(ww):
  104. z = int((abs(ww2-x)**2+abs(hh2-y)**2)**0.5)
  105. if x < ww2:
  106. t = 0
  107. if y > hh2:
  108. t = 2
  109. else:
  110. t = 1
  111. if y > hh2:
  112. t = 3
  113. try:
  114. rrr[z] += [(t,x,y)]
  115. except:
  116. rrr[z] = [(t,x,y)]
  117. 0
  118.  
  119. b = 5
  120. qqq = len(rrr)-1
  121. spiral = 0
  122. while 1:
  123. v = 512*b/360.0
  124. for z in range(qqq):
  125. rrr[z].sort()
  126. L = len(rrr[z])
  127. L2 = L/2
  128. r2 = rrr[z][L2:]
  129. rrr[z] = rrr[z][:L2]+r2[::-1]
  130. spiral += 1.2
  131. for p,x,y in rrr[z]:
  132. p = (math.degrees(math.atan2(256-x,256-y))+180)*v
  133. pix[x+y*hh] = ttt[int(p+spiral)%tL]
  134. print b
  135. img.putdata(pix)
  136. imgTk = ImageTk.PhotoImage(img)
  137. canvas.create_image(1, 1, anchor=NW, image=imgTk)
  138. root.update()
  139. 0
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement