Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_prism.py
- from Tkinter import *
- from PIL import Image, ImageTk
- from math import *
- import random
- root = Tk()
- root.title("Tk prism")
- root.geometry("500x500")
- wi = 500
- he = 500
- w = Canvas(root, width=wi, height=he)
- w.pack()
- img = Image.new( 'RGB', (wi,he))
- cols = {}
- for i in range(0, 256):
- cols[0,i] = abs(int(128 - 127 * sin(i * pi / 32)))
- cols[1,i] = abs(int(128 - 127 * sin(i * pi / 64)))
- cols[2,i] = abs(int(128 - 127 * sin(i * pi / 128)))
- xy = []
- for y in range(0, he):
- for x in range(0, wi):
- c = int(cos(x/50)*128+cos(y/50)*32 + sin((x+y)/16)*32)
- if c > 255 : c = c - 256
- if c < 0 : c = 256 + c
- r = cols[0, c]
- if r > 255 : r = r - 256
- if r < 0 : r = 256 + c
- g = cols[1, c]
- if g > 255 : g = g - 256
- if g < 0 : g = 256 + c
- b = cols[2, c]
- if b > 255 : b = b - 256
- if b < 0 : b = 256 + c
- xy.append((r, g, b))
- #print xy
- img.putdata(tuple(xy))
- imgTk = ImageTk.PhotoImage(img)
- w.create_image(0, 0, anchor=NW, image=imgTk)
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement