outfly/src/nature.rs

34 lines
1.3 KiB
Rust
Raw Normal View History

// This stuff here, this stuff is messy. Nobody wants to deal with this,
// nobody cares how it works, but I guess we need it as an ingredient for
// the universe *sigh* so here we go.
2024-03-18 22:53:52 +00:00
pub const OXYGEN_USE_KG_PER_S: f32 = 1e-5;
pub const OXY_S: f32 = OXYGEN_USE_KG_PER_S;
pub const OXY_M: f32 = OXYGEN_USE_KG_PER_S * 60.0;
pub const OXY_H: f32 = OXYGEN_USE_KG_PER_S * 60.0 * 60.0;
pub const OXY_D: f32 = OXYGEN_USE_KG_PER_S * 60.0 * 60.0 * 24.0;
pub fn star_color_index_to_rgb(color_index: f32) -> (f32, f32, f32) {
let temperature = 4600.0 * ((1.0 / (0.92 * color_index + 1.7)) + (1.0 / (0.92 * color_index + 0.62)));
let (red, green, blue) = if temperature <= 6600.0 {
let red = 255.0;
let green = 99.4708025861 * (temperature / 100.0).ln() - 161.1195681661;
let blue = if temperature <= 2000.0 {
0.0
} else {
138.5177312231 * ((temperature / 100.0) - 10.0).ln() - 305.0447927307
};
(red, green, blue)
} else {
let red = 329.698727446 * ((temperature / 100.0 - 60.0).powf(-0.1332047592));
let green = 288.1221695283 * ((temperature / 100.0 - 60.0).powf(-0.0755148492));
let blue = 255.0;
(red, green, blue)
};
let clamp = |x: f32| -> f32 { (x / 255.0).max(0.0).min(1.0) };
return (clamp(red), clamp(green), clamp(blue))
}