Advertisement
here2share

# Tk_tri_wave.py

May 10th, 2020
1,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. # Tk_tri_wave.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 = 120
  15. hh = 120
  16. waves = {}
  17. ppp = list('abc')
  18. for i in (69,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 = waves
  32. a2 = len(waves[a])
  33. b2 = len(waves[b])
  34. c2 = len(waves[c])
  35.  
  36. zzz = 0
  37. root=Tk()
  38. canvas = Canvas(root,width=ww,height=hh,bg='black')
  39. canvas.grid(row=0,column=0,sticky=N+S+E+W)
  40.  
  41. def high():
  42.     aa = waves[a][zzz%a2]
  43.     bb = waves[b][zzz%b2]
  44.     cc = waves[c][zzz%c2]
  45.     return (aa+bb+cc)/3
  46. 0
  47.  
  48. wide = []
  49. while zzz != ww+2:
  50.     wide.append(high())
  51.     zzz += 1
  52.  
  53. def plot():
  54.     color = oRGB(rgb)
  55.     x = xx+2
  56.     canvas.create_line((x, 0, x, yy), fill=color)
  57. 0
  58. def oRGB(rgb):
  59.     r,g,b = rgb
  60.     return "#%02x%02x%02x" % (r,g,b)
  61. 0
  62. while 1:
  63.     canvas.delete('all')
  64.     for xx in range(0,ww):
  65.         yy = wide[xx]
  66.         rgb = 255,255,0
  67.         plot()
  68.     canvas.update()
  69.     wide.append(high())
  70.     wide.pop(0)
  71.     zzz += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement