Struct ansinator_terminal_colors::TermColor
source · [−]Expand description
Abstraction for Terminal colors
Container of Terminal Color, for storing is RGB value and it’s color index.
Fields
r: u8
Red channel
g: u8
Green channel
b: u8
Blue channel
index: u8
Color Index
As specified from https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
Implementations
sourceimpl TermColor
impl TermColor
sourcepub fn from(r: u8, g: u8, b: u8) -> Self
pub fn from(r: u8, g: u8, b: u8) -> Self
Create a TermColor from 24bit RGB color by finding the best approximate color in the 256 Terminal colors palette
Find the terminal color that minimizes the asimilarity of a general RGB color by a exahustive calculation of quadrances, return the TermColor which minimizes the quadrance.
sourcepub fn quadrance(&self, tcolor: &TermColor) -> f64
pub fn quadrance(&self, tcolor: &TermColor) -> f64
Calculates the quadrance of two TermColors to measure similarity
The quadrance is a quadratic measure to compare how similar two colors are and is defined by the sum of the squares of the differences of each channel when the two color are equal the quadrance is equal to zero, The biggest the quadrance can be is when comparing opposite colors (as white and black) and can be shown to be three times the maximum value of the channels, in this case each channels has an maximum equal to 255 thus the quadrance(white, black) = 3 * 255 * 255.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for TermColor
impl Send for TermColor
impl Sync for TermColor
impl Unpin for TermColor
impl UnwindSafe for TermColor
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more