Repository navigation
Expand file tree
/
Copy pathrocket_engine_plot.py
More file actions
97 lines (80 loc) · 2.81 KB
/
Copy pathrocket_engine_plot.py
File metadata and controls
97 lines (80 loc) · 2.81 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
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
import pygame
import sys
import rocket_engine
# 1. Inicjalizacja Pygame i większe okno
pygame.init()
WIDTH, HEIGHT = 1000, 750
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Rocket Flight Simulator - C++ Engine")
clock = pygame.time.Clock()
# 2. Utworzenie rakiety z C++
rocket = rocket_engine.Rocket()
# Parametry: fuel_mass, rocket_mass, burn_rate, exhaust_velocity, diameter, drag_coeff
rocket.set_parameters(15.0, 10.0, 0.5, 2000.0, 0.1, 0.3)
# Kolory i czcionki
BLACK = (15, 15, 20)
WHITE = (240, 240, 240)
RED = (255, 70, 70)
ORANGE = (255, 165, 0)
GREEN = (70, 255, 100)
GRAY = (100, 100, 100)
BLUE = (50, 100, 200)
font = pygame.font.SysFont("Consolas", 18)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Krok fizyki co 0.05s dla płynności
rocket.update_step(0.05)
# Pobranie stanu bezpośrednio z C++
alt = rocket.get_height()
vel = rocket.get_velocity()
acc = rocket.get_acceleration()
fuel = rocket.get_fuel_mass()
burning = rocket.is_burning()
screen.fill(BLACK)
#Dynamic camera followng the rocket
scale = 0.05
center_x = WIDTH // 2
center_y = HEIGHT // 2 + 100 # Rakieta stoi nieco poniżej środka ekranu
# Obliczamy gdzie znajduje się Ziemia na ekranie względem rakiety
ground_y = center_y + (alt * scale)
# Rysujemy ziemię
if ground_y < HEIGHT:
pygame.draw.rect(screen, GRAY, (0, ground_y, WIDTH, HEIGHT - ground_y + 100))
# Rysowanie płomienia (gdy silnik pracuje)
if burning and alt > 0:
pygame.draw.polygon(screen, ORANGE, [
(center_x - 6, center_y + 20),
(center_x + 6, center_y + 20),
(center_x, center_y + 45)
])
pygame.draw.polygon(screen, RED, [
(center_x - 3, center_y + 20),
(center_x + 3, center_y + 20),
(center_x, center_y + 35)
])
# Korpus rakiety (zawsze w punkcie center_x, center_y)
pygame.draw.rect(screen, WHITE, (center_x - 8, center_y - 20, 16, 40))
pygame.draw.polygon(screen, RED, [
(center_x - 8, center_y - 20),
(center_x + 8, center_y - 20),
(center_x, center_y - 35)
])
# TELEMETRIA (Panel po lewej)
telemetry = [
f"ALTITUDE: {alt:.1f} m",
f"VELOCITY: {vel:.1f} m/s",
f"ACCELERATION: {acc:.1f} m/s^2",
f"FUEL MASS: {fuel:.1f} kg",
f"ENGINE STATE: {'BURNING' if burning else 'COASTING'}"
]
for i, line in enumerate(telemetry):
color = GREEN if "BURNING" in line else (RED if "COASTING" in line else WHITE)
text_surface = font.render(line, True, color)
screen.blit(text_surface, (20, 20 + i * 25))
pygame.display.flip()
clock.tick(60)
pygame.quit()
sys.exit()