here2share

# Tk_plasma_ripple.py

Sep 13th, 2020
1,085
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Tk_plasma_ripple.py
  2.  
  3. import random
  4.  
  5. from Tkinter import *
  6. from PIL import Image, ImageTk
  7.  
  8. bell_curve = '''1000 1000 1000 1000 1000 999 999 999 999 999 999 999 999 999 998 998 998 998 998 998 998 998 997 997 997 997 997 997 996 996 996 995 995 995 995 994 994 993 993 992 992 992 991 991 990 990 989 989 988 987 987 986 985 984 984 983 982 981 979 978 977 976 975 974 973 972 971 970 968 967 966 964 963 961 960 958 957 955 953 951 949 947 945 943 941 939 937 935 933 930 928 926 924 921 919 916 914 912 909 906 904 901 899 896 893 890 887 884 881 878 875 872 869 866 862 859 855 852 848 845 842 838 835 831 828 825 821 818 814 811 808 804 801 797 794 791 787 784 781 777 774 771 767 764 761 757 754 751 747 744 741 737 734 731 727 724 721 717 714 711 707 704 700 697 694 690 687 684 680 677 674 670 667 664 660 657 653 650 647 643 640 637 633 630 626 623 620 616 613 609 606 603 599 596 593 589 586 582 579 576 572 569 565 561 557 553 549 546 542 538 535 531 528 524 521 518 514 511 507 504 500 497 494 490 487 483 480 477 473 470 466 463 460 456 453 449 446 442 439 436 432 429 425 422 419 415 412 408 405 402 398 395 391 388 384 381 378 374 371 367 364 361 357 354 350 347 344 340 337 333 330 326 323 320 316 313 309 306 303 299 296 292 289 286 282 279 275 272 268 265 262 258 255 251 248 245 241 238 235 232 229 226 224 221 218 215 212 209 206 204 201 198 195 193 190 187 185 182 179 177 174 172 169 167 164 162 160 157 155 153 151 149 147 145 143 141 139 137 135 133 131 129 127 125 123 121 119 117 116 114 112 110 108 107 105 103 101 99 97 96 94 92 91 89 88 86 85 83 82 80 79 78 76 75 74 72 71 70 69 67 66 65 63 62 61 60 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 33 32 31 30 30 29 28 27 27 26 25 25 24 24 23 22 22 21 20 20 19 19 18 17 17 16 16 15 15 14 13 13 12 12 11 11 11 10 10 9 9 9 8 8 8 7 7 7 7 6 6 6 5 5 5 5 5 4 4 4 4 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1'''.split()
  9.  
  10. zzz = ' '.join([z for z in bell_curve[::-1]])
  11.  
  12. bell_curve = [int(z)*0.001 for z in bell_curve]
  13. bell_curve += bell_curve[::-1]
  14.  
  15. root = Tk()
  16.  
  17. ww = 600
  18. hh = 600
  19. canvas = Canvas(root, width=ww, height=hh)
  20. canvas.grid()
  21.  
  22. pixels = [(255,0,0)]*(ww*hh)
  23. img = Image.new("RGB",(ww,hh))
  24. seq = []
  25.  
  26. label = Label(root, image=None)
  27. label.grid(row=0, column=0)
  28.  
  29. rainbow=[]
  30. def z(r,g,b):
  31.     rainbow.append((r,g,b))
  32. r,g,b=255,0,0
  33. for g in range(256):
  34.     z(r,g,b)
  35. for r in range(254, -1, -1):
  36.     z(r,g,b)
  37. for b in range(256):
  38.     z(r,g,b)
  39. for g in range(254, -1, -1):
  40.     z(r,g,b)
  41. for r in range(256):
  42.     z(r,g,b)
  43. for b in range(254, -1, -1):
  44.     z(r,g,b)
  45. max_rgb=len(rainbow)
  46. rainbow = rainbow[1:-1]+rainbow[::-1]
  47.  
  48. def color(z):
  49.     return rainbow[int(z)%max_rgb]
  50.        
  51. def plot():
  52.     r2 = cv.index
  53.     print cv.index
  54.     for y in range(hh):
  55.         for x in range(ww):
  56.             i = int(x+y*ww)
  57.             sig=0
  58.             x2,y2,r = blobs[0]
  59.             d = (abs(x-y)**2+abs(y-y2)**2)**0.5
  60.             sig += bell_curve[int(d*6)%1000]*300
  61.             for x2,y2,r in blobs[1:]:
  62.                 d = (abs(x-x2)**2+abs(y-y2)**2)**0.5
  63.                 sig += bell_curve[int(d*1.5)%1000]*r
  64.             pixels[i] = color(sig)
  65.     cv.index += 200
  66. #
  67. class Cv():
  68.     0
  69. cv = Cv()
  70. cv.index = 200
  71. delay = 0
  72. while 1:
  73.     blobs = [0]*6
  74.     L = len(blobs)
  75.     for i in range(L):
  76.         blobs[i]=[random.randint(20,ww),random.randint(20,hh),random.randint(250,500)]
  77.     plot()
  78.     img.putdata(tuple(pixels))
  79.     photo = ImageTk.PhotoImage(img)
  80.     label.configure(image=photo)
  81.     label.update()
  82.  
RAW Paste Data