-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlack_Hole_polarized_light.py
93 lines (71 loc) · 3.04 KB
/
Black_Hole_polarized_light.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
import pygame
import random
import math
# Initialize Pygame
pygame.init()
# Set up the screen
screen_size = (1800, 1000)
screen = pygame.display.set_mode(screen_size)
# Define the black hole
black_hole_pos = (900, 500)
black_hole_radius = 40
black_hole_mass = 1.989 * 10**7
event_horizon_radius = 2 * black_hole_radius
# Define the photons
photons = []
for i in range(200):
photons.append({
"pos": (1800, i*6),
"velocity": (-2, 0),
"color": (5, 45, 5),
"trail": []
})
# Define the gravitational constant
G = 0.01
# Main game loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Clear the screen
screen.fill((0, 0, 0))
# Draw the black hole
# Update the photons
for photon in photons:
# Calculate the distance between the photon and the black hole
distance = math.sqrt((photon["pos"][0] - black_hole_pos[0])**2 + (photon["pos"][1] - black_hole_pos[1])**2)
# Check if the photon is within the event horizon
if distance < event_horizon_radius:
# The photon is within the event horizon and will be captured by the black hole
photon["color"] = (234, 180, 80)
else:
# The photon is outside the event horizon and will continue to move under the influence of gravity
# Calculate the gravitational force acting on the photon
force = G * black_hole_mass / distance**2
# Calculate the direction of the force
force_direction = math.atan2(black_hole_pos[1] - photon["pos"][1], black_hole_pos[0] - photon["pos"][0])
# Update the velocity of the photon
scaling_factor = 0.1 # this is the new scaling factor
photon["velocity"] = (photon["velocity"][0] + scaling_factor * force * math.cos(force_direction), photon["velocity"][1] + scaling_factor * force * math.sin(force_direction))
# Update the position of the photon
photon["pos"] = (photon["pos"][0] + photon["velocity"][0], photon["pos"][1] + photon["velocity"][1])
# Add the current position to the trail
photon["trail"].append(photon["pos"])
# Draw the photon
pygame.draw.circle(screen, photon["color"], (int(photon["pos"][0]), int(photon["pos"][1])), 2)
# Draw the trail
dash_length = 1
gap_length = 1
for i in range(1, len(photon["trail"])):
if i % (dash_length + gap_length) < dash_length:
# pygame.draw.line(screen, photon["color"], photon["trail"][i-1], photon["trail"][i], 1, pygame.style.DASHED)
pygame.draw.aaline(screen, photon["color"], photon["trail"][i-1], photon["trail"][i])
# Draw black hole
# Draw the event horizon
pygame.draw.circle(screen, (0, 0, 0), black_hole_pos, event_horizon_radius, 0)
pygame.draw.circle(screen, (0, 0, 0), black_hole_pos, black_hole_radius, 1)
# Update the screen
pygame.display.update()
# Quit Pygame
pygame.quit()