Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_RGB_by_sum.py
- from Tkinter import *
- from random import *
- from math import *
- from PIL import Image, ImageTk
- def rgb2hex(r,g,b):
- return '#%02X%02X%02X'%(r,g,b)
- root = Tk()
- root.title("RGB by sum")
- ww = 1400
- hh = 680
- canvas = Canvas(root, width=ww, height=hh, bg="gray")
- canvas.pack(side=TOP)
- print 'please wait...'
- rgb = [(r,g,b) for r in range(0,255) for g in range(0,255) for b in range(0,255)]
- print 'almost there...'
- L = len(rgb)
- incr = L/(ww*hh)
- rgb.sort(key=sum)
- print 'a little more patience...'
- rgb = [rgb[z*incr] for z in range(ww*hh)]
- img = Image.new("RGB",(ww, hh))
- img.putdata(rgb)
- imgTk = ImageTk.PhotoImage(img)
- canvas.create_image(0, 0, anchor=NW, image=imgTk)
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement