67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
import tkinter as tk
|
|
from PIL import Image, ImageDraw, ImageTk
|
|
|
|
class FlightSimulatorApp:
|
|
def __init__(self, root, map_path):
|
|
self.root = root
|
|
self.root.title("Simulatore Tracce Aeree")
|
|
|
|
# Carica mappa da file
|
|
original_map = Image.open(map_path).convert("RGB")
|
|
self.width, self.height = original_map.size
|
|
|
|
# Tkinter canvas
|
|
self.canvas = tk.Canvas(root, width=self.width, height=self.height)
|
|
self.canvas.pack()
|
|
|
|
# Mappa di sfondo
|
|
self.base_map = original_map
|
|
|
|
# Lista aerei
|
|
self.aircrafts = [
|
|
{"x": 100, "y": 100, "vx": 2, "vy": 1},
|
|
{"x": 200, "y": 250, "vx": 1, "vy": -1},
|
|
{"x": 300, "y": 400, "vx": -1, "vy": 2},
|
|
]
|
|
self.tracks = [[] for _ in self.aircrafts]
|
|
|
|
# Avvio animazione
|
|
self.update_frame()
|
|
|
|
def update_frame(self):
|
|
# Copia mappa
|
|
frame = self.base_map.copy()
|
|
draw = ImageDraw.Draw(frame)
|
|
|
|
# Disegna aerei e tracce
|
|
for i, aircraft in enumerate(self.aircrafts):
|
|
aircraft["x"] += aircraft["vx"]
|
|
aircraft["y"] += aircraft["vy"]
|
|
|
|
# Salva traccia
|
|
self.tracks[i].append((aircraft["x"], aircraft["y"]))
|
|
|
|
# Traccia gialla
|
|
if len(self.tracks[i]) > 1:
|
|
draw.line(self.tracks[i], fill='yellow', width=2)
|
|
|
|
# Aereo rosso
|
|
x, y = aircraft["x"], aircraft["y"]
|
|
draw.ellipse((x-5, y-5, x+5, y+5), fill='red')
|
|
|
|
# Aggiorna immagine Tkinter
|
|
self.tk_image = ImageTk.PhotoImage(frame)
|
|
self.canvas.create_image(0, 0, anchor='nw', image=self.tk_image)
|
|
|
|
# Frame successivo
|
|
self.root.after(100, self.update_frame)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Percorso immagine di sfondo (mappa)
|
|
mappa_path = "mappa.png" # ← Cambia con il nome del tuo file
|
|
|
|
root = tk.Tk()
|
|
app = FlightSimulatorApp(root, mappa_path)
|
|
root.mainloop()
|