Advertisement
here2share

# Tk_prism.py

Sep 30th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. # Tk_prism.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. from math import *
  6. import random
  7.  
  8. root = Tk()
  9. root.title("Tk prism")
  10. root.geometry("500x500")
  11. wi = 500
  12. he = 500
  13. w = Canvas(root, width=wi, height=he)
  14. w.pack()
  15.  
  16. img = Image.new( 'RGB', (wi,he))
  17. cols = {}
  18.  
  19. for i in range(0, 256):
  20.     cols[0,i] = abs(int(128 - 127 * sin(i * pi / 32)))
  21.     cols[1,i] = abs(int(128 - 127 * sin(i * pi / 64)))
  22.     cols[2,i] = abs(int(128 - 127 * sin(i * pi / 128)))
  23.  
  24. xy = []
  25. for y in range(0, he):
  26.     for x in range(0, wi):
  27.         c = int(cos(x/50)*128+cos(y/50)*32 + sin((x+y)/16)*32)
  28.         if c > 255 : c = c - 256
  29.         if c < 0 : c = 256 + c
  30.         r = cols[0, c]
  31.         if r > 255 : r = r - 256
  32.         if r < 0 : r = 256 + c
  33.         g = cols[1, c]
  34.         if g > 255 : g = g - 256
  35.         if g < 0 : g = 256 + c
  36.         b = cols[2, c]
  37.         if b > 255 : b = b - 256
  38.         if b < 0 : b = 256 + c
  39.         xy.append((r, g, b))
  40. #print xy
  41. img.putdata(tuple(xy))
  42. imgTk = ImageTk.PhotoImage(img)
  43. w.create_image(0, 0, anchor=NW, image=imgTk)
  44. root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement