forked from Seconb/Roblox-Colorbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFOVOverlay.py
More file actions
60 lines (52 loc) · 2.09 KB
/
FOVOverlay.py
File metadata and controls
60 lines (52 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import tkinter as tk
from PIL import Image, ImageDraw, ImageTk
class FOVOverlay:
def __init__(self):
self.root = tk.Tk()
self.root.withdraw()
self.overlays = []
def create_circle_overlay(self, radius, color, alpha=255):
image = Image.new('RGBA', (radius*2, radius*2), (0, 0, 0, 0))
draw = ImageDraw.Draw(image)
draw.ellipse(
(0, 0, radius*2-1, radius*2-1),
outline=color + (alpha,),
width=2
)
return image
def show(self, cam_radius, aim_radius, cam_color, aim_color):
self.clear()
# Create camera FOV overlay
cam_image = self.create_circle_overlay(cam_radius, cam_color)
cam_photo = ImageTk.PhotoImage(cam_image)
cam_window = self.create_overlay_window(cam_radius)
cam_label = tk.Label(cam_window, image=cam_photo, bg='black')
cam_label.image = cam_photo # type: ignore
cam_label.pack()
self.overlays.append(cam_window)
# Create the aim FOV overlay
aim_image = self.create_circle_overlay(aim_radius, aim_color)
aim_photo = ImageTk.PhotoImage(aim_image)
aim_window = self.create_overlay_window(aim_radius)
aim_label = tk.Label(aim_window, image=aim_photo, bg='black')
aim_label.image = aim_photo # type: ignore
aim_label.pack()
self.overlays.append(aim_window)
def create_overlay_window(self, radius):
window = tk.Toplevel(self.root)
window.overrideredirect(True)
window.attributes('-topmost', True)
window.attributes('-transparentcolor', 'black')
screen_width = self.root.winfo_screenwidth()
screen_height = self.root.winfo_screenheight()
window.geometry(f'+{(screen_width - radius*2)//2}+{(screen_height - radius*2)//2}')
return window
def clear(self):
for overlay in self.overlays:
try:
overlay.destroy()
except tk.TclError:
pass
self.overlays = []
def update(self):
self.root.update()