here2share

# tk_whitehole_effect.py

Sep 24th, 2025
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. # tk_whitehole_effect.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk, ImageDraw, ImageFont
  5. import math
  6.  
  7. WW, HH = 640, 640
  8. cx, cy = WW // 2, HH // 2
  9. root = tk.Tk()
  10. root.geometry('+0+0')
  11. canvas = tk.Canvas(root, width=WW, height=HH)
  12. canvas.pack()
  13.  
  14. current_mouse_x, current_mouse_y = cx, cy
  15.  
  16. def get_degrees(x, y):
  17.     dx = x - cx
  18.     dy = y - cy
  19.     degrees = math.degrees(math.atan2(-dy, dx))
  20.     if degrees < 0:
  21.         degrees += 360
  22.     return degrees
  23.  
  24. def o(a, b, c=3):
  25.     return min(a+c, max(a-c, b))
  26.  
  27. def get_distance_from_center(x, y):
  28.     dx = x - cx
  29.     dy = y - cy
  30.     distance = math.sqrt(dx * dx + dy * dy)
  31.     return distance
  32.  
  33. def on_drag(event):
  34.     global current_mouse_x, current_mouse_y
  35.     current_mouse_x, current_mouse_y = event.x, event.y
  36.     active_pixels.add((event.x, event.y))
  37.  
  38. def on_motion(event):
  39.     global current_mouse_x, current_mouse_y
  40.     current_mouse_x, current_mouse_y = event.x, event.y
  41.    
  42. zoom_cache = {}
  43. for y in range(HH):
  44.     for x in range(WW):
  45.         degrees = get_degrees(x, y)
  46.         angle = math.radians(degrees)
  47.         distance = get_distance_from_center(x, y) + 10
  48.         nx = cx + distance * math.cos(angle)
  49.         ny = cy - distance * math.sin(angle)
  50.         nx, ny = o(x, nx), o(y, ny)
  51.         zoom_cache[(x, y)] = {1: (int(nx), int(ny))}
  52. active_pixels = set()
  53.  
  54. canvas.bind("<B1-Motion>", on_drag)
  55. canvas.bind("<Motion>", on_motion)
  56.  
  57. while 1:
  58.     img = Image.new('RGB', (WW, HH), (255, 255, 255))
  59.     updated_pixels = set()
  60.     for (x, y) in active_pixels:
  61.         try:
  62.             src_x, src_y = zoom_cache[(x, y)][1]
  63.             img.putpixel((src_x, src_y), (0, 0, 0))
  64.             updated_pixels.add((src_x, src_y))
  65.         except:
  66.             0
  67.     photo = ImageTk.PhotoImage(img)
  68.     canvas.create_image(0, 0, anchor=tk.NW, image=photo)
  69.     active_pixels = updated_pixels
  70.     root.update()
Advertisement
Add Comment
Please, Sign In to add comment