Advertisement
here2share

# tk_540x540_Gradient.py

Jan 8th, 2024
1,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. # tk_540x540_Gradient.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5.  
  6. root = Tk()
  7. root.title("540x540 Gradient")
  8. ww = 540
  9. hh = 540
  10. root.geometry("%dx%d+-10+0"%(ww,hh))
  11. canvas = Canvas(root, width=ww, height=hh)
  12. canvas.pack()
  13.  
  14. D = 20
  15. t = [z for z in range(256)]
  16. a = {}
  17. for z in t:
  18.     v = min(z,256-D)
  19.     a[z] = range(v,v+D)
  20. p = {}
  21. def gen(w,h):
  22.     w2 = w/255.0
  23.     h2 = h/255.0
  24.     for y in range(h):
  25.         cy = int(y/h2)
  26.         for x in range(w):
  27.             cx = int(x/w2)
  28.             r = 255-cx
  29.             g = 255-cy
  30.             b = int((cx+cy)/2)
  31.             for bbb in a[b]:
  32.                 z = (r,g,bbb)
  33.                 try:
  34.                     p[z]
  35.                 except:
  36.                     break
  37.             rgb.append(z)
  38.             p[z] = 1
  39.  
  40. rgb = []
  41. gen(ww,hh)
  42. img = Image.new('RGB', (ww,hh))
  43. img.putdata(rgb)
  44. imgTk = ImageTk.PhotoImage(img)
  45. canvas.create_image(0, 0, anchor=NW, image=imgTk)
  46. root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement