here2share

# tk_plasma_attack.py

May 11th, 2020 (edited)
2,644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. # tk_plasma_attack.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5. import math
  6. import colorsys
  7.  
  8. z = 0
  9. RGBs = []
  10. while True:
  11.     z += 0.0007
  12.     t = colorsys.hsv_to_rgb(z, 1, 1)
  13.     t = tuple([int(round(c * 255.0)) for c in t])
  14.     if t in RGBs:
  15.         break
  16.     else:
  17.         RGBs.append(t)
  18. Lc = len(RGBs)
  19.  
  20. z = 0
  21. angles = 2000
  22. incr = 360.0 / angles
  23. xy = {}
  24. while z < 360:
  25.     s = math.cos(math.radians(z)) * 10000
  26.     xy[len(xy)] = max(-9999, min(9999, int(s)))
  27.     z += incr
  28. waves = [xy[z] for z in range(len(xy))]
  29. Lw = len(waves)
  30.  
  31. def w(z):
  32.     return waves[z % Lw]
  33.  
  34. def oRGB(rgb):
  35.     r, g, b = rgb
  36.     return "#%02x%02x%02x" % (r, g, b)
  37.  
  38. ww = 200
  39. hh = 200
  40. root = Tk()
  41. root.title("Tk_plasma_attack")
  42. root.geometry("%dx%d+0+0" % (ww, hh))
  43. canvas = Canvas(root, width=ww, height=hh)
  44. canvas.grid()
  45.  
  46. img = Image.new("RGB", (ww, hh))
  47.  
  48. zz = [z for z in range(5, 100)]
  49. zz = zz + zz[::-1]
  50. px, py = 1, 1
  51.  
  52. while True:
  53.     for xx in zz:
  54.         py += 0.1
  55.         yy = int(py)
  56.         pix = []
  57.  
  58.         def cycle(x, y, xx, yy):
  59.             return sum([
  60.                 waves[z % angles] for z in (
  61.                     w(x + yy) - w(y - yy),
  62.                     w((xx + yy) * 3) // 2 - w(y - x + xx)
  63.                 )
  64.             ]) // 20 + y * 7
  65.  
  66.         for x in range(ww):
  67.             for y in range(hh):
  68.                 pix.append(RGBs[cycle(x, y, xx, yy) % Lc])
  69.         id = ':'.join([str(int(z)) for z in (px, py)])
  70.         px = xx
  71.         print('Plasma Image ' + id)
  72.         img.putdata(pix)
  73.         imgTk = ImageTk.PhotoImage(img)
  74.         canvas.create_image(0, 0, anchor=NW, image=imgTk)
  75.         canvas.img = imgTk  # Prevent garbage collection
  76.         canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment