Advertisement
here2share

# Tk_RGB_plasma.py

Oct 21st, 2022 (edited)
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. # Tk_RGB_plasma.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5. from math import sin, pi, radians, degrees
  6.  
  7. ww = 270
  8. hh = 270
  9. root = Tk()
  10. root.title("Tk_RGB_plasma")
  11. root.geometry("%dx%d+0+0"%(ww,hh))
  12. canvas = Canvas(root, width=ww, height=hh)
  13. canvas.grid()
  14.  
  15. img = Image.new("RGB",(ww,hh), "white")
  16.  
  17. cc = {}
  18. for x in range(ww):
  19.     for y in range(hh):
  20.         cc[x,y] = 0
  21.  
  22. xy = []
  23. x2 = 256.0/ww
  24. y2 = 256.0/hh
  25. for y in range(hh):
  26.     b = int(y*y2)
  27.     for x in range(ww):
  28.         a = int(x*x2)
  29.         c = cc[a,b]
  30.         xy += [(a,b,c)]
  31.         cc[a,b] = c+1
  32. zz = xy[:]
  33.  
  34. o255 = [z for z in range(256)]
  35. o255 = o255[1:-1] + o255[::-1]
  36. Lo = len(o255)
  37.  
  38. fade = [z for z in range(30)]
  39. fade = fade[1:-1] + fade[::-1]
  40. Lx = len(fade)
  41.  
  42. Lz = range(ww*hh)
  43.  
  44. def draw():
  45.     img.putdata(xy)
  46.     imgTk = ImageTk.PhotoImage(img)
  47.     canvas.create_image(0, 0, anchor=NW, image=imgTk)
  48.     root.update()
  49.  
  50. t = 1
  51. while 1: # to keep looping
  52.     draw()
  53.     ttt = []
  54.     for i in Lz:
  55.         rgb = []
  56.         for j in (0,1,2):
  57.             rgb += [(zz[i][j] + t + ((j + 1) * 1.001)) % Lo]
  58.         r,g,b = rgb
  59.         chk = o255[int(r)%Lo], o255[int(g)%Lo], o255[int(b)%Lo]
  60.         xy[i] = chk
  61.         zz[i] = rgb
  62.     t += 0.01
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement