Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # even_odd_zoom.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageFilter
- WW, HH = 640, 640
- CX, CY = WW // 2, HH // 2
- root = tk.Tk()
- root.title("# even_odd_zoom.py")
- canvas = tk.Canvas(root, width=WW, height=HH)
- root.geometry("+10+10")
- canvas.pack()
- grid_colors = {
- (0, 0): (255, 255, 255), (0, 1): (255, 255, 0), (0, 2): (0, 255, 0),
- (1, 0): (255, 165, 0), (1, 1): (128, 128, 128), (1, 2): (0, 0, 255),
- (2, 0): (255, 0, 0), (2, 1): (128, 0, 128), (2, 2): (0, 0, 0)
- }
- small_img = Image.new('RGB', (3, 3))
- for y in range(3):
- for x in range(3):
- small_img.putpixel((x, y), grid_colors[(x, y)])
- img = small_img.resize((WW, HH), Image.LANCZOS)
- static_img = img.copy()
- def plus_one_modulo():
- new_img = img.point(lambda p: min(255, p + 4) if p % 2 == 0 else max(0, p - 4))
- return new_img
- scale = 10
- def update_frame():
- global img, photo
- img = img.crop((scale, scale, WW - scale, HH - scale))
- img = img.resize((WW, HH), Image.LANCZOS)
- img = plus_one_modulo()
- photo = ImageTk.PhotoImage(img)
- canvas.delete('all')
- canvas.create_image(0, 0, image=photo, anchor=tk.NW)
- root.after(1, update_frame)
- photo = ImageTk.PhotoImage(img)
- canvas.create_image(0, 0, image=photo, anchor=tk.NW)
- root.after(1, update_frame)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement