Advertisement
here2share

# tk_solidcolors_at16_ani.py

Jul 21st, 2023 (edited)
1,243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. # tk_solidcolors_at16_ani.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk, ImageFilter, ImageDraw
  5. import copy
  6.  
  7. ww = 256
  8. hh = 256
  9. cx, cy = ww//2, hh//2
  10.  
  11. def rgb2hex(r,g,b):
  12.     return '#%02X%02X%02X'%(r,g,b)
  13.  
  14. rgb = range(0, 256, 10)
  15. colors = [rgb2hex(r, g, b) for r in rgb for g in rgb for b in rgb]
  16.  
  17. img = Image.new('RGB', (ww, hh), (0, 0, 0))
  18. draw = {}
  19. draw[0] = ImageDraw.Draw(img)
  20. blur_radius = 0.03 * min(img.size)
  21.  
  22. def display(new_img):
  23.     tkimg = ImageTk.PhotoImage(new_img)
  24.     canvas.create_image((cx, cy), image=tkimg)
  25.     canvas.update()
  26.  
  27. root = Tk()
  28. root.title("tk_solidcolors_at16_ani")
  29. root.geometry("%dx%d+10+10"%(ww,hh))
  30. canvas = Canvas(root, width=ww, height=hh, bg='white')
  31. canvas.pack(side=LEFT, fill=BOTH, expand=True)
  32.  
  33. sz = 16
  34. span = ww//sz
  35. c = 0
  36. xy = range(0, sz*span, sz)
  37.        
  38. sharpening_masks = []
  39.  
  40. while 1:
  41.     for y in xy:
  42.         c = (c + 2) % 11
  43.         for x in xy:
  44.             color = colors.pop(c)
  45.             colors.append(color)
  46.             draw[0].rectangle((x, y, x+sz, y+sz), fill=color, outline=color)
  47.             c = (c + 3) % 11
  48.  
  49.     draw['target'] = img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
  50.  
  51.     # Apply a lambda function to round the RGB values to the nearest multiple of 50
  52.     draw['target'] = draw['target'].point(lambda p: round(p / 50) * 50)
  53.  
  54.     display(draw['target'])
  55.  
  56. '''
  57.    if draw['target'] not in sharpening_masks[:1]:
  58.        sharpening_masks += [draw['target']]
  59.    else:
  60.        break
  61.  
  62. print(len(sharpening_masks))
  63. '''
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement