Advertisement
here2share

# Tk_plasma_ripple.py

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