mod camera;
pub mod braille;
mod pixel;
pub mod surface;
pub use camera::Camera;
pub use pixel::{PixelBuffer, apply_edge_aa, apply_silhouette_edges, apply_ssao, apply_tone_mapping, fill_depth_gaps};
pub use surface::{generate_surface, SurfaceAtom};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Representation {
Backbone,
#[default]
Cartoon,
Surface,
}
impl Representation {
pub fn next(self) -> Self {
match self {
Representation::Backbone => Representation::Cartoon,
Representation::Cartoon => Representation::Surface,
Representation::Surface => Representation::Backbone,
}
}
pub fn name(&self) -> &'static str {
match self {
Representation::Backbone => "Backbone",
Representation::Cartoon => "Cartoon",
Representation::Surface => "Surface",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ColorScheme {
#[default]
Chain,
Rainbow,
SecondaryStructure,
}
impl ColorScheme {
pub fn next(self) -> Self {
match self {
ColorScheme::Chain => ColorScheme::Rainbow,
ColorScheme::Rainbow => ColorScheme::SecondaryStructure,
ColorScheme::SecondaryStructure => ColorScheme::Chain,
}
}
pub fn name(&self) -> &'static str {
match self {
ColorScheme::Chain => "Chain",
ColorScheme::Rainbow => "Rainbow",
ColorScheme::SecondaryStructure => "Secondary Structure",
}
}
}
pub fn chain_color(chain_id: char) -> (u8, u8, u8) {
const CHAIN_COLORS: [(u8, u8, u8); 10] = [
(30, 144, 255), (255, 165, 0), (50, 205, 50), (255, 99, 71), (138, 43, 226), (0, 206, 209), (255, 215, 0), (199, 21, 133), (0, 191, 255), (255, 105, 180), ];
let idx = match chain_id {
'A'..='J' => (chain_id as u8 - b'A') as usize,
'a'..='j' => (chain_id as u8 - b'a') as usize,
_ => 0,
};
CHAIN_COLORS[idx % CHAIN_COLORS.len()]
}
pub fn rainbow_color(t: f32) -> (u8, u8, u8) {
let t = t.clamp(0.0, 1.0);
let r: u8;
let g: u8;
let b: u8;
if t < 0.25 {
let f = t * 4.0;
r = 0;
g = (255.0 * f) as u8;
b = 255;
} else if t < 0.5 {
let f = (t - 0.25) * 4.0;
r = 0;
g = 255;
b = (255.0 * (1.0 - f)) as u8;
} else if t < 0.75 {
let f = (t - 0.5) * 4.0;
r = (255.0 * f) as u8;
g = 255;
b = 0;
} else {
let f = (t - 0.75) * 4.0;
r = 255;
g = (255.0 * (1.0 - f)) as u8;
b = 0;
}
(r, g, b)
}