Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_whitehole_effect.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageDraw, ImageFont
- import math
- WW, HH = 640, 640
- cx, cy = WW // 2, HH // 2
- root = tk.Tk()
- root.geometry('+0+0')
- canvas = tk.Canvas(root, width=WW, height=HH)
- canvas.pack()
- current_mouse_x, current_mouse_y = cx, cy
- def get_degrees(x, y):
- dx = x - cx
- dy = y - cy
- degrees = math.degrees(math.atan2(-dy, dx))
- if degrees < 0:
- degrees += 360
- return degrees
- def o(a, b, c=3):
- return min(a+c, max(a-c, b))
- def get_distance_from_center(x, y):
- dx = x - cx
- dy = y - cy
- distance = math.sqrt(dx * dx + dy * dy)
- return distance
- def on_drag(event):
- global current_mouse_x, current_mouse_y
- current_mouse_x, current_mouse_y = event.x, event.y
- active_pixels.add((event.x, event.y))
- def on_motion(event):
- global current_mouse_x, current_mouse_y
- current_mouse_x, current_mouse_y = event.x, event.y
- zoom_cache = {}
- for y in range(HH):
- for x in range(WW):
- degrees = get_degrees(x, y)
- angle = math.radians(degrees)
- distance = get_distance_from_center(x, y) + 10
- nx = cx + distance * math.cos(angle)
- ny = cy - distance * math.sin(angle)
- nx, ny = o(x, nx), o(y, ny)
- zoom_cache[(x, y)] = {1: (int(nx), int(ny))}
- active_pixels = set()
- canvas.bind("<B1-Motion>", on_drag)
- canvas.bind("<Motion>", on_motion)
- while 1:
- img = Image.new('RGB', (WW, HH), (255, 255, 255))
- updated_pixels = set()
- for (x, y) in active_pixels:
- try:
- src_x, src_y = zoom_cache[(x, y)][1]
- img.putpixel((src_x, src_y), (0, 0, 0))
- updated_pixels.add((src_x, src_y))
- except:
- 0
- photo = ImageTk.PhotoImage(img)
- canvas.create_image(0, 0, anchor=tk.NW, image=photo)
- active_pixels = updated_pixels
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment