Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_540x540_Gradient.py
- from tkinter import *
- from PIL import Image, ImageTk
- root = Tk()
- root.title("540x540 Gradient")
- ww = 540
- hh = 540
- root.geometry("%dx%d+-10+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.pack()
- D = 20
- t = [z for z in range(256)]
- a = {}
- for z in t:
- v = min(z,256-D)
- a[z] = range(v,v+D)
- p = {}
- def gen(w,h):
- w2 = w/255.0
- h2 = h/255.0
- for y in range(h):
- cy = int(y/h2)
- for x in range(w):
- cx = int(x/w2)
- r = 255-cx
- g = 255-cy
- b = int((cx+cy)/2)
- for bbb in a[b]:
- z = (r,g,bbb)
- try:
- p[z]
- except:
- break
- rgb.append(z)
- p[z] = 1
- rgb = []
- gen(ww,hh)
- img = Image.new('RGB', (ww,hh))
- img.putdata(rgb)
- imgTk = ImageTk.PhotoImage(img)
- canvas.create_image(0, 0, anchor=NW, image=imgTk)
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement