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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use super::Animation;
use crate::render::Canvas;
/// Accretion disk with gravitational lensing distortion, M87-inspired
pub struct Blackhole {
_unused: (),
}
impl Blackhole {
#[allow(unused_variables)]
pub fn new(_width: usize, _height: usize, _scale: f64) -> Self {
Blackhole { _unused: () }
}
}
impl Animation for Blackhole {
fn name(&self) -> &str {
"blackhole"
}
fn update(&mut self, canvas: &mut Canvas, _dt: f64, time: f64) {
let w = canvas.width as f64;
let h = canvas.height as f64;
let cx = w * 0.5;
let cy = h * 0.5;
let bh_radius = (w.min(h) * 0.08).max(4.0);
let disk_outer = bh_radius * 5.0;
let disk_inner = bh_radius * 1.5;
canvas.clear();
for y in 0..canvas.height {
for x in 0..canvas.width {
let fx = x as f64;
let fy = y as f64;
let dx = fx - cx;
let dy = fy - cy;
let dist = (dx * dx + dy * dy).sqrt();
let angle = dy.atan2(dx);
// Event horizon - pure black
if dist < bh_radius {
continue;
}
// Photon ring - bright thin ring at ~1.5x event horizon
let photon_ring_r = bh_radius * 1.5;
let photon_dist = (dist - photon_ring_r).abs();
if photon_dist < 1.0 {
let ring_bright = (1.0 - photon_dist) * 0.8;
canvas.set_colored(x, y, ring_bright, 255, 200, 100);
continue;
}
// Accretion disk
if dist > disk_inner && dist < disk_outer {
// Disk is in the orbital plane - simulate viewing angle
// M87-style: asymmetric brightness due to relativistic beaming
let disk_frac = (dist - disk_inner) / (disk_outer - disk_inner);
// Doppler beaming - one side brighter than the other
let doppler = (angle - time * 0.3).cos() * 0.4 + 0.6;
// Spiral structure in the disk
let spiral =
((angle * 3.0 - dist * 0.2 + time * 0.8).sin() * 0.3 + 0.7).max(0.0);
// Temperature gradient: hotter near center
let temperature = 1.0 - disk_frac * 0.7;
let intensity = temperature * doppler * spiral;
// Gravitational lensing: bend the disk appearance near the hole
let lensing = if dist < bh_radius * 3.0 {
let lens_factor = (dist - bh_radius) / (bh_radius * 2.0);
lens_factor.clamp(0.3, 1.0)
} else {
1.0
};
let v = (intensity * lensing).clamp(0.0, 1.0);
if v > 0.01 {
let (r, g, b) = accretion_color(v, temperature);
canvas.set_colored(x, y, v, r, g, b);
}
} else if dist >= disk_outer {
// Faint glow beyond disk
let glow = ((dist - disk_outer) / (disk_outer * 0.5)).neg_exp_falloff();
if glow > 0.01 {
let r = (80.0 * glow) as u8;
let g = (40.0 * glow) as u8;
let b = (20.0 * glow) as u8;
canvas.set_colored(x, y, glow * 0.2, r, g, b);
}
// Background stars
let star_hash = ((fx * 127.1 + fy * 311.7).sin() * 43758.5453).fract().abs();
if star_hash > 0.998 {
// Gravitational lensing of stars near the black hole
let star_bright = if dist < disk_outer * 1.5 {
let stretch = (dist / (disk_outer * 1.5)).powi(2);
0.3 * stretch
} else {
0.3
};
let twinkle =
((time * 2.0 + star_hash * 50.0).sin() * 0.5 + 0.5) * star_bright;
canvas.set_colored(x, y, twinkle, 200, 200, 230);
}
}
}
}
}
}
trait FalloffExt {
fn neg_exp_falloff(self) -> f64;
}
impl FalloffExt for f64 {
fn neg_exp_falloff(self) -> f64 {
(-self * 3.0).exp()
}
}
fn accretion_color(v: f64, temperature: f64) -> (u8, u8, u8) {
// M87-inspired: orange-yellow core, reddish outer
let t = temperature;
if t > 0.7 {
// Hot inner: bright orange-yellow
let f = (t - 0.7) / 0.3;
(255, (180.0 + 75.0 * f) as u8, (40.0 + 80.0 * f * v) as u8)
} else if t > 0.4 {
// Mid: orange-red
let f = (t - 0.4) / 0.3;
(
(200.0 + 55.0 * f) as u8,
(80.0 + 100.0 * f) as u8,
(10.0 + 30.0 * f) as u8,
)
} else {
// Cool outer: dark red
let f = t / 0.4;
(
(80.0 + 120.0 * f) as u8,
(20.0 + 60.0 * f) as u8,
(5.0 + 5.0 * f) as u8,
)
}
}