Advertisement
here2share

# Tk_RGB_by_sum.py

Sep 21st, 2021
1,031
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. # Tk_RGB_by_sum.py
  2.  
  3. from Tkinter import *
  4. from random import *
  5. from math import *
  6. from PIL import Image, ImageTk
  7.  
  8. def rgb2hex(r,g,b):
  9.     return '#%02X%02X%02X'%(r,g,b)
  10.  
  11. root = Tk()
  12. root.title("RGB by sum")
  13.  
  14. ww = 1400
  15. hh = 680
  16.  
  17. canvas = Canvas(root, width=ww, height=hh, bg="gray")
  18. canvas.pack(side=TOP)
  19.  
  20. print 'please wait...'
  21. rgb = [(r,g,b) for r in range(0,255) for g in range(0,255) for b in range(0,255)]
  22. print 'almost there...'
  23.  
  24. L = len(rgb)
  25. incr = L/(ww*hh)
  26. rgb.sort(key=sum)
  27. print 'a little more patience...'
  28. rgb = [rgb[z*incr] for z in range(ww*hh)]
  29.  
  30. img = Image.new("RGB",(ww, hh))
  31.  
  32. img.putdata(rgb)
  33. imgTk = ImageTk.PhotoImage(img)
  34. canvas.create_image(0, 0, anchor=NW, image=imgTk)
  35. canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement