Advertisement
here2share

# Tk_Gradient_Art_Generator.py

Oct 11th, 2019 (edited)
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. # Tk_Gradient_Art_Generator.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5. import random
  6. import math
  7.  
  8. root = Tk()
  9. root.title("Gradient Art Generator")
  10. wt = 400
  11. ht = 400
  12. root.geometry("%dx%d+-10+0"%(wt,ht))
  13. canvas = Canvas(root, width=wt, height=ht)
  14. canvas.pack()
  15.  
  16. def art_gen(w,h):
  17.     xy = []
  18.     for x in range(w):
  19.         for y in range(h):
  20.             z = random.randint(-300,1600)
  21.             z = min(255,max(0,z))
  22.             xy.append([(x,y),z])
  23.     xy = dict(xy)
  24.     px = 128
  25.     for cx in range(w):
  26.         for cy in range(h):
  27.             z = xy[(int(cx/10), cy)]
  28.             px = (px*20+z)/21.0
  29.             rgb[cx][cy].append(int(px))
  30. 0
  31.  
  32. while 1:
  33.     rgb = [[[] for x in range(wt)] for y in range(ht)]
  34.     [art_gen(wt,ht) for z in 'rgb']
  35.     rgb = tuple([tuple(i) for z in rgb for i in z])
  36.  
  37.     img = Image.new('RGB', (wt,ht))
  38.     img.putdata(rgb)
  39.     imgTk = ImageTk.PhotoImage(img)
  40.     canvas.create_image(0, 0, anchor=NW, image=imgTk)
  41.     root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement