Advertisement
here2share

# Tk_2D_Waves_Of_Four.py

Mar 13th, 2021
1,190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. # Tk_2D_Waves_Of_Four.py
  2.  
  3. from itertools import permutations
  4.  
  5. L = range(0,255,10)
  6. L[-1] = 255
  7. combos = [z for z in permutations(L, 4)]
  8.  
  9. from PIL import Image, ImageTk, ImageDraw
  10. from Tkinter import *
  11. import PIL
  12. import math
  13.  
  14. ww = 400
  15. hh = 400
  16. waves = {}
  17. ppp = list('abcd')
  18. for i in (69,180,123,299):
  19.     incr = (360.0/i)
  20.     xy = {}
  21.     p = ppp.pop()
  22.     waves[p] = []
  23.     z = 0
  24.     while z < 360:
  25.         s = math.cos(math.radians(z))*(hh/2-20)+(hh/2)
  26.         xy[len(xy)] = min(600,int(s))
  27.         z += incr
  28.     t = [xy[z] for z in range(len(xy))]
  29.     waves[p].extend(t)
  30. 0
  31. a,b,c,d = waves
  32. a2 = len(waves[a])
  33. b2 = len(waves[b])
  34. c2 = len(waves[c])
  35. d2 = len(waves[d])
  36.  
  37. zzz = 0
  38. root=Tk()
  39. canvas = Canvas(root,width=ww,height=hh,bg='black')
  40. canvas.grid(row=0,column=0,sticky=N+S+E+W)
  41.  
  42. def high():
  43.     aa = waves[a][zzz%a2]
  44.     bb = waves[b][zzz%b2]
  45.     cc = waves[c][zzz%c2]
  46.     dd = waves[d][zzz%d2]
  47.     return (aa+bb+cc+dd)/4
  48. 0
  49.  
  50. wide = []
  51. while zzz != ww+2:
  52.     wide.append(high())
  53.     zzz += 1
  54.  
  55. def plot():
  56.     color = oRGB(rgb)
  57.     x = xx+2
  58.     canvas.create_line((x, 0, x, yy), fill=color)
  59. 0
  60. def oRGB(rgb):
  61.     r,g,b = rgb
  62.     return "#%02x%02x%02x" % (r,g,b)
  63. 0
  64. while 1:
  65.     canvas.delete('all')
  66.     for xx in range(0,ww):
  67.         yy = wide[xx]
  68.         rgb = 255,255,0
  69.         plot()
  70.     canvas.update()
  71.     wide.append(high())
  72.     wide.pop(0)
  73.     zzz += 1
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement