-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrameZen_Script.py
126 lines (103 loc) · 5.17 KB
/
FrameZen_Script.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import tkinter as tk
from tkinter import messagebox
import math
from PIL import Image, ImageTk # Import Pillow
class FortniteTrajectoryApp:
def __init__(self, root):
self.root = root
self.root.title("Fortnite Trajectory Calculator")
# Canvas dimensions
self.canvas_width = 1000
self.canvas_height = 700
# Load Fortnite map image using Pillow
try:
self.bg_image = Image.open("fortnite_map.png") # Replace with the path to your image
self.bg_image = self.bg_image.resize((self.canvas_width, self.canvas_height)) # Resize to fit the canvas
self.bg_image = ImageTk.PhotoImage(self.bg_image) # Convert to Tkinter-compatible format
except Exception as e:
messagebox.showerror("Error", f"Failed to load image: {e}")
return
self.canvas = tk.Canvas(root, width=self.canvas_width, height=self.canvas_height)
self.canvas.pack()
# Display map as background
self.canvas.create_image(0, 0, image=self.bg_image, anchor=tk.NW)
# Buttons
self.place_bus_path_btn = tk.Button(root, text="Place Battle Bus Path", command=self.set_bus_path)
self.place_bus_path_btn.pack(pady=5)
self.place_poi_btn = tk.Button(root, text="Set Drop Point (POI)", command=self.set_poi)
self.place_poi_btn.pack(pady=5)
self.calculate_btn = tk.Button(root, text="Calculate Trajectory", command=self.calculate_trajectory,
state=tk.DISABLED)
self.calculate_btn.pack(pady=5)
# Variables for user inputs
self.bus_path = []
self.poi = None
self.mode = None
def set_bus_path(self):
self.mode = "bus_path"
self.bus_path = []
self.poi = None
self.calculate_btn.config(state=tk.DISABLED)
self.canvas.delete("all")
# Redraw background after clearing canvas
self.canvas.create_image(0, 0, image=self.bg_image, anchor=tk.NW)
messagebox.showinfo("Instructions", "Click twice on the map to place the battle bus path.")
def set_poi(self):
if len(self.bus_path) < 2:
messagebox.showerror("Error", "Please define the battle bus path first.")
return
self.mode = "poi"
self.poi = None
messagebox.showinfo("Instructions", "Click on the map to place the drop point (POI).")
def calculate_trajectory(self):
if len(self.bus_path) < 2 or not self.poi:
messagebox.showerror("Error", "You must set both the bus path and POI before calculating.")
return
# Extract bus points and POI
bus_start, bus_end = self.bus_path
poi = self.poi
# Calculate trajectory
result = self.calculate_optimal_jump(bus_start, bus_end, poi)
# Display result
messagebox.showinfo(
"Result",
f"Optimal Jump Angle: {result['angle']:.2f}°\n"
f"Distance to POI: {result['distance']:.2f} units\n"
f"Optimal Jump Point: {result['optimal_jump_point']}"
)
# Draw optimal jump point
jump_x, jump_y = result["optimal_jump_point"]
self.canvas.create_oval(jump_x - 5, jump_y - 5, jump_x + 5, jump_y + 5, fill="green", outline="black")
self.canvas.create_line(jump_x, jump_y, poi[0], poi[1], fill="red", dash=(4, 2))
def calculate_optimal_jump(self, bus_start, bus_end, poi):
bus_vector = (bus_end[0] - bus_start[0], bus_end[1] - bus_start[1])
poi_vector = (poi[0] - bus_start[0], poi[1] - bus_start[1])
bus_length = math.sqrt(bus_vector[0] ** 2 + bus_vector[1] ** 2)
bus_unit = (bus_vector[0] / bus_length, bus_vector[1] / bus_length)
projection_length = poi_vector[0] * bus_unit[0] + poi_vector[1] * bus_unit[1]
projection = (bus_start[0] + projection_length * bus_unit[0],
bus_start[1] + projection_length * bus_unit[1])
distance = math.sqrt((poi[0] - projection[0]) ** 2 + (poi[1] - projection[1]) ** 2)
angle = math.degrees(math.atan2(poi[1] - projection[1], poi[0] - projection[0]))
return {"angle": angle, "distance": distance, "optimal_jump_point": projection}
def on_canvas_click(self, event):
if self.mode == "bus_path" and len(self.bus_path) < 2:
self.bus_path.append((event.x, event.y))
self.canvas.create_oval(event.x - 5, event.y - 5, event.x + 5, event.y + 5, fill="blue", outline="black")
if len(self.bus_path) == 2:
self.canvas.create_line(
self.bus_path[0][0], self.bus_path[0][1],
self.bus_path[1][0], self.bus_path[1][1],
fill="blue", width=2
)
elif self.mode == "poi" and not self.poi:
self.poi = (event.x, event.y)
self.canvas.create_oval(event.x - 5, event.y - 5, event.x + 5, event.y + 5, fill="red", outline="black")
self.calculate_btn.config(state=tk.NORMAL)
# Main application
if __name__ == "__main__":
root = tk.Tk()
app = FortniteTrajectoryApp(root)
# Bind canvas click event
app.canvas.bind("<Button-1>", app.on_canvas_click)
root.mainloop()