Advertisement
here2share

# Tk_2D_Waves_Of_Four_2.py

Mar 14th, 2021 (edited)
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. # Tk_2D_Waves_Of_Four_2.py
  2.  
  3. from PIL import Image, ImageTk, ImageDraw
  4. from Tkinter import *
  5. import PIL
  6. import math
  7. import random
  8.  
  9. from itertools import permutations
  10.  
  11. many = 4
  12.  
  13. L = range(72,450,9)
  14. COMBOS = [z for z in permutations(L, many)]
  15. random.shuffle(COMBOS)
  16. COMBOS = [z for zzz in COMBOS for z in zzz]
  17.  
  18. ww = 1400
  19. hh = 700
  20. waves = {}
  21. def PiXY(i,j):
  22.     incr = (360.0/i)
  23.     waves[j] = []
  24.     z = 0
  25.     while z < 360:
  26.         y = math.cos(math.radians(z))*(hh/2-20)+(hh/2)
  27.         z += incr
  28.         waves[j].append(int(y))
  29. 0
  30.  
  31. def store_wave(j):
  32.     i = COMBOS.pop(0)
  33.     COMBOS.append(i)
  34.     PiXY(i,j)
  35.  
  36. for z in range(many):
  37.     store_wave(z)
  38. print
  39.  
  40. zzz = 0
  41. root=Tk()
  42. canvas = Canvas(root,width=ww,height=hh,bg='black')
  43. canvas.grid(row=0,column=0,sticky=N+S+E+W)
  44.  
  45. def high():
  46.     L = len(waves)
  47.     t = []
  48.     for z in range(L):
  49.         try:
  50.             t += [waves[z].pop()]
  51.         except:
  52.             store_wave(z)
  53.             t += [waves[z].pop()]
  54.     return sum(t)/L
  55. 0
  56. def plot():
  57.     color = oRGB(rgb)
  58.     x = xx+2
  59.     canvas.create_line((x, 0, x, yy), fill=color)
  60. 0
  61. def oRGB(rgb):
  62.     r,g,b = rgb
  63.     return "#%02x%02x%02x" % (r,g,b)
  64. 0
  65. while 1:
  66.     canvas.delete('all')
  67.     for xx in range(0,ww):
  68.         rgb = 255,255,0 # yellow
  69.         yy = high()
  70.         plot()
  71.     canvas.update()
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement