here2share

# Tk_rgb_brightness.py

Oct 15th, 2019 (edited)
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. # Tk_rgb_brightness.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. from math import *
  6. import random
  7. import re
  8.  
  9. colors = 4096*4096
  10.  
  11. w = h = 600
  12.  
  13. xyc = []
  14. for y in range(0,h):
  15.     for x in range(0,w):
  16.         rgb = int((y*6.4)*4096+((x*6.4)%4096))
  17.         r,g,b = (rgb & 0xff, (rgb >> 8) & 0xff, rgb >> 16)
  18.         lum = sqrt(0.299*r + 0.587*g + 0.114*b)
  19.         xyc.append([lum,(r,g,b)])
  20. xyc.sort(key=lambda z: z[0])
  21. root = Tk()
  22. root.title("Tk rgb brightness")
  23. canvas = Canvas(root, width=w, height=h)
  24. canvas.pack()
  25. for y in range(0,h):
  26.     zzz,xyc = xyc[:w],xyc[w:]
  27.     # zzz.sort(key=lambda z: z[1][1]+z[1][2])
  28.     for x in range(0,w):
  29.         z,cx = zzz.pop()
  30.         canvas.create_line((x,y,x+1,y+1),fill='#%02x%02x%02x' % cx)
  31.     root.update()
  32. 0
  33. root.mainloop()
Add Comment
Please, Sign In to add comment