Advertisement
here2share

# tk_Piranha_Frenzy.py

Jun 25th, 2024
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. # tk_Piranha_Frenzy.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk, ImageFilter, ImageOps, ImageDraw
  5. import math
  6. import time
  7. import random
  8.  
  9. ww = 600
  10. hh = 600
  11.  
  12. root = tk.Tk()
  13. root.title("tk Piranha Frenzy")
  14.  
  15. canvas = tk.Canvas(root, width=ww+300, height=hh)
  16. canvas.pack()
  17.  
  18. def create_layers():
  19.     img = Image.new("L", (ww+200, hh+200))
  20.     dr = ImageDraw.Draw(img)
  21.     dr.rectangle(((0, 0), (ww+200, (hh+200) * 0.80)), fill='white')
  22.     pixels = list(img.getdata())
  23.     random.shuffle(pixels)
  24.     img.putdata(pixels)
  25.     return img
  26.  
  27. image_A = create_layers()
  28. image_B = create_layers()
  29.  
  30. while 1:
  31.     image_A = image_A.filter(ImageFilter.BLUR)
  32.     image_B = image_B.filter(ImageFilter.BLUR)
  33.  
  34.     image_A = image_A.point(lambda i: (i + 1) % 255)
  35.     image_B = image_B.point(lambda i: (i + 1) % 254)
  36.  
  37.     image = Image.blend(image_A, image_B, 0.5)
  38.    
  39.     left = 100
  40.     top = 100
  41.     right = ww + 100
  42.     bottom = hh + 100
  43.  
  44.     image = image.crop((left, top, right, bottom))
  45.  
  46.     photo = ImageTk.PhotoImage(image)
  47.     canvas.create_image(0, 0, image=photo, anchor=tk.NW)
  48.     root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement