Trait color_brewery::RGBColor
source · pub trait RGBColor: Sized {
const HUE: Hue<Self> = _;
Show 47 methods
// Required methods
fn to_rgba(&self) -> RGBA<f64>;
fn from_rgba(rgba: RGBA<f64>) -> Self;
// Provided methods
fn gradient(&self, c1: &Self) -> Gradient<Self> { ... }
fn palettes(len: usize) -> PaletteFind<Self> { ... }
fn magma() -> Palette<Self> { ... }
fn inferno() -> Palette<Self> { ... }
fn plasma() -> Palette<Self> { ... }
fn viridis() -> Palette<Self> { ... }
fn cividis() -> Palette<Self> { ... }
fn twilight() -> Palette<Self> { ... }
fn turbo() -> Palette<Self> { ... }
fn ylgn() -> PaletteIter<Self> ⓘ { ... }
fn ylgnbu() -> PaletteIter<Self> ⓘ { ... }
fn gnbu() -> PaletteIter<Self> ⓘ { ... }
fn bugn() -> PaletteIter<Self> ⓘ { ... }
fn pubugn() -> PaletteIter<Self> ⓘ { ... }
fn pubu() -> PaletteIter<Self> ⓘ { ... }
fn bupu() -> PaletteIter<Self> ⓘ { ... }
fn rdpu() -> PaletteIter<Self> ⓘ { ... }
fn purd() -> PaletteIter<Self> ⓘ { ... }
fn orrd() -> PaletteIter<Self> ⓘ { ... }
fn ylorrd() -> PaletteIter<Self> ⓘ { ... }
fn ylorbr() -> PaletteIter<Self> ⓘ { ... }
fn purples() -> PaletteIter<Self> ⓘ { ... }
fn blues() -> PaletteIter<Self> ⓘ { ... }
fn greens() -> PaletteIter<Self> ⓘ { ... }
fn oranges() -> PaletteIter<Self> ⓘ { ... }
fn reds() -> PaletteIter<Self> ⓘ { ... }
fn greys() -> PaletteIter<Self> ⓘ { ... }
fn puor() -> PaletteIter<Self> ⓘ { ... }
fn brbg() -> PaletteIter<Self> ⓘ { ... }
fn prgn() -> PaletteIter<Self> ⓘ { ... }
fn piyg() -> PaletteIter<Self> ⓘ { ... }
fn rdbu() -> PaletteIter<Self> ⓘ { ... }
fn rdgy() -> PaletteIter<Self> ⓘ { ... }
fn rdylbu() -> PaletteIter<Self> ⓘ { ... }
fn spectral() -> PaletteIter<Self> ⓘ { ... }
fn rdylgn() -> PaletteIter<Self> ⓘ { ... }
fn set1() -> PaletteIter<Self> ⓘ { ... }
fn pastel1() -> PaletteIter<Self> ⓘ { ... }
fn set2() -> PaletteIter<Self> ⓘ { ... }
fn pastel2() -> PaletteIter<Self> ⓘ { ... }
fn dark2() -> PaletteIter<Self> ⓘ { ... }
fn set3() -> PaletteIter<Self> ⓘ { ... }
fn paired() -> PaletteIter<Self> ⓘ { ... }
fn accent() -> PaletteIter<Self> ⓘ { ... }
fn to_gray(&self) -> Self { ... }
}
Expand description
Specifies the methods a RGB color encoding must provide.
Provided Associated Constants§
Required Methods§
Provided Methods§
sourcefn gradient(&self, c1: &Self) -> Gradient<Self>
fn gradient(&self, c1: &Self) -> Gradient<Self>
Return a gradient from color c0
to color c1
.
Example
use rgb::RGB8;
use color_brewery::{RGBColor, ColorRange};
let red = RGB8::new(255,0, 0);
let blue = RGB8::new(0, 0, 255);
let grad = red.gradient(&blue);
let rgb = grad.rgb(0.5);
sourcefn palettes(len: usize) -> PaletteFind<Self>
fn palettes(len: usize) -> PaletteFind<Self>
Find palettes matching certain criteria.
sourcefn magma() -> Palette<Self>
fn magma() -> Palette<Self>
Matplotlib magma color scheme.
Examples found in repository?
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
fn main() -> Result<(), Err> {
let mut fh = BufWriter::new(File::create("gradient.html")?);
writeln!(fh, "<html>\n\
<head>\n\
<title>Color_brewery: test {}</title>\n\
</head>\n\
<body>",
env::args().next().unwrap())?;
writeln!(fh, "<h3>Hue</h3>")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 10, 43, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 30, 13, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 150, 1, "")?;
writeln!(fh, "<h3>Gradients</h3>")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 10, 43, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 30, 13, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 255, 0], 150, 1,
"Best <a href=\"https://youtu.be/XjHzLUnHeM0?t=230\"
>to avoid red and green</a>.")?;
gradient(&mut fh, [0, 0, 0], [255, 255, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 128], [144, 144, 255], 150, 1, "")?;
writeln!(fh, "<h3>Palettes (sequential and diverging)</h3>")?;
for (comment, p) in [("viridis", RGB8::viridis()),
("magma", RGB8::magma()),
("inferno", RGB8::inferno()),
("plasma", RGB8::plasma()),
("viridis", RGB8::viridis()),
("cividis", RGB8::cividis()),
("twilight", RGB8::twilight()),
("turbo", RGB8::turbo())] {
palette(&mut fh, p, 256, 1, comment)?;
}
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
palette(&mut fh, p, 128, 1,
&format!("{} (interpolated)", stringify!($name)))?;
} )*
}}
palette!(ylgn, ylgnbu, gnbu, bugn, pubugn, pubu, bupu, rdpu, purd,
orrd, ylorrd, ylorbr, purples, blues, greens, oranges,
reds, greys,
// Diverging
puor, brbg, prgn, piyg, rdbu, rdgy, rdylbu, spectral, rdylgn);
writeln!(fh, "<h3>Palettes (others)</h3>")?;
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
} )*
}}
palette!(set1, pastel1, set2, pastel2, dark2, set3, paired, accent);
writeln!(fh, "</body>\n\
</html>")?;
Ok(())
}
sourcefn inferno() -> Palette<Self>
fn inferno() -> Palette<Self>
Matplotlib inferno color scheme.
Examples found in repository?
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
fn main() -> Result<(), Err> {
let mut fh = BufWriter::new(File::create("gradient.html")?);
writeln!(fh, "<html>\n\
<head>\n\
<title>Color_brewery: test {}</title>\n\
</head>\n\
<body>",
env::args().next().unwrap())?;
writeln!(fh, "<h3>Hue</h3>")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 10, 43, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 30, 13, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 150, 1, "")?;
writeln!(fh, "<h3>Gradients</h3>")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 10, 43, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 30, 13, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 255, 0], 150, 1,
"Best <a href=\"https://youtu.be/XjHzLUnHeM0?t=230\"
>to avoid red and green</a>.")?;
gradient(&mut fh, [0, 0, 0], [255, 255, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 128], [144, 144, 255], 150, 1, "")?;
writeln!(fh, "<h3>Palettes (sequential and diverging)</h3>")?;
for (comment, p) in [("viridis", RGB8::viridis()),
("magma", RGB8::magma()),
("inferno", RGB8::inferno()),
("plasma", RGB8::plasma()),
("viridis", RGB8::viridis()),
("cividis", RGB8::cividis()),
("twilight", RGB8::twilight()),
("turbo", RGB8::turbo())] {
palette(&mut fh, p, 256, 1, comment)?;
}
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
palette(&mut fh, p, 128, 1,
&format!("{} (interpolated)", stringify!($name)))?;
} )*
}}
palette!(ylgn, ylgnbu, gnbu, bugn, pubugn, pubu, bupu, rdpu, purd,
orrd, ylorrd, ylorbr, purples, blues, greens, oranges,
reds, greys,
// Diverging
puor, brbg, prgn, piyg, rdbu, rdgy, rdylbu, spectral, rdylgn);
writeln!(fh, "<h3>Palettes (others)</h3>")?;
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
} )*
}}
palette!(set1, pastel1, set2, pastel2, dark2, set3, paired, accent);
writeln!(fh, "</body>\n\
</html>")?;
Ok(())
}
sourcefn plasma() -> Palette<Self>
fn plasma() -> Palette<Self>
Matplotlib plasma color scheme.
Examples found in repository?
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
fn main() -> Result<(), Err> {
let mut fh = BufWriter::new(File::create("gradient.html")?);
writeln!(fh, "<html>\n\
<head>\n\
<title>Color_brewery: test {}</title>\n\
</head>\n\
<body>",
env::args().next().unwrap())?;
writeln!(fh, "<h3>Hue</h3>")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 10, 43, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 30, 13, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 150, 1, "")?;
writeln!(fh, "<h3>Gradients</h3>")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 10, 43, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 30, 13, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 255, 0], 150, 1,
"Best <a href=\"https://youtu.be/XjHzLUnHeM0?t=230\"
>to avoid red and green</a>.")?;
gradient(&mut fh, [0, 0, 0], [255, 255, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 128], [144, 144, 255], 150, 1, "")?;
writeln!(fh, "<h3>Palettes (sequential and diverging)</h3>")?;
for (comment, p) in [("viridis", RGB8::viridis()),
("magma", RGB8::magma()),
("inferno", RGB8::inferno()),
("plasma", RGB8::plasma()),
("viridis", RGB8::viridis()),
("cividis", RGB8::cividis()),
("twilight", RGB8::twilight()),
("turbo", RGB8::turbo())] {
palette(&mut fh, p, 256, 1, comment)?;
}
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
palette(&mut fh, p, 128, 1,
&format!("{} (interpolated)", stringify!($name)))?;
} )*
}}
palette!(ylgn, ylgnbu, gnbu, bugn, pubugn, pubu, bupu, rdpu, purd,
orrd, ylorrd, ylorbr, purples, blues, greens, oranges,
reds, greys,
// Diverging
puor, brbg, prgn, piyg, rdbu, rdgy, rdylbu, spectral, rdylgn);
writeln!(fh, "<h3>Palettes (others)</h3>")?;
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
} )*
}}
palette!(set1, pastel1, set2, pastel2, dark2, set3, paired, accent);
writeln!(fh, "</body>\n\
</html>")?;
Ok(())
}
sourcefn viridis() -> Palette<Self>
fn viridis() -> Palette<Self>
Matplotlib viridis color scheme.
Examples found in repository?
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
fn main() -> Result<(), Err> {
let mut fh = BufWriter::new(File::create("gradient.html")?);
writeln!(fh, "<html>\n\
<head>\n\
<title>Color_brewery: test {}</title>\n\
</head>\n\
<body>",
env::args().next().unwrap())?;
writeln!(fh, "<h3>Hue</h3>")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 10, 43, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 30, 13, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 150, 1, "")?;
writeln!(fh, "<h3>Gradients</h3>")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 10, 43, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 30, 13, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 255, 0], 150, 1,
"Best <a href=\"https://youtu.be/XjHzLUnHeM0?t=230\"
>to avoid red and green</a>.")?;
gradient(&mut fh, [0, 0, 0], [255, 255, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 128], [144, 144, 255], 150, 1, "")?;
writeln!(fh, "<h3>Palettes (sequential and diverging)</h3>")?;
for (comment, p) in [("viridis", RGB8::viridis()),
("magma", RGB8::magma()),
("inferno", RGB8::inferno()),
("plasma", RGB8::plasma()),
("viridis", RGB8::viridis()),
("cividis", RGB8::cividis()),
("twilight", RGB8::twilight()),
("turbo", RGB8::turbo())] {
palette(&mut fh, p, 256, 1, comment)?;
}
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
palette(&mut fh, p, 128, 1,
&format!("{} (interpolated)", stringify!($name)))?;
} )*
}}
palette!(ylgn, ylgnbu, gnbu, bugn, pubugn, pubu, bupu, rdpu, purd,
orrd, ylorrd, ylorbr, purples, blues, greens, oranges,
reds, greys,
// Diverging
puor, brbg, prgn, piyg, rdbu, rdgy, rdylbu, spectral, rdylgn);
writeln!(fh, "<h3>Palettes (others)</h3>")?;
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
} )*
}}
palette!(set1, pastel1, set2, pastel2, dark2, set3, paired, accent);
writeln!(fh, "</body>\n\
</html>")?;
Ok(())
}
sourcefn cividis() -> Palette<Self>
fn cividis() -> Palette<Self>
Matplotlib cividis color scheme.
Examples found in repository?
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
fn main() -> Result<(), Err> {
let mut fh = BufWriter::new(File::create("gradient.html")?);
writeln!(fh, "<html>\n\
<head>\n\
<title>Color_brewery: test {}</title>\n\
</head>\n\
<body>",
env::args().next().unwrap())?;
writeln!(fh, "<h3>Hue</h3>")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 10, 43, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 30, 13, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 150, 1, "")?;
writeln!(fh, "<h3>Gradients</h3>")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 10, 43, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 30, 13, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 255, 0], 150, 1,
"Best <a href=\"https://youtu.be/XjHzLUnHeM0?t=230\"
>to avoid red and green</a>.")?;
gradient(&mut fh, [0, 0, 0], [255, 255, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 128], [144, 144, 255], 150, 1, "")?;
writeln!(fh, "<h3>Palettes (sequential and diverging)</h3>")?;
for (comment, p) in [("viridis", RGB8::viridis()),
("magma", RGB8::magma()),
("inferno", RGB8::inferno()),
("plasma", RGB8::plasma()),
("viridis", RGB8::viridis()),
("cividis", RGB8::cividis()),
("twilight", RGB8::twilight()),
("turbo", RGB8::turbo())] {
palette(&mut fh, p, 256, 1, comment)?;
}
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
palette(&mut fh, p, 128, 1,
&format!("{} (interpolated)", stringify!($name)))?;
} )*
}}
palette!(ylgn, ylgnbu, gnbu, bugn, pubugn, pubu, bupu, rdpu, purd,
orrd, ylorrd, ylorbr, purples, blues, greens, oranges,
reds, greys,
// Diverging
puor, brbg, prgn, piyg, rdbu, rdgy, rdylbu, spectral, rdylgn);
writeln!(fh, "<h3>Palettes (others)</h3>")?;
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
} )*
}}
palette!(set1, pastel1, set2, pastel2, dark2, set3, paired, accent);
writeln!(fh, "</body>\n\
</html>")?;
Ok(())
}
sourcefn twilight() -> Palette<Self>
fn twilight() -> Palette<Self>
Matplotlib twilight color scheme.
Examples found in repository?
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
fn main() -> Result<(), Err> {
let mut fh = BufWriter::new(File::create("gradient.html")?);
writeln!(fh, "<html>\n\
<head>\n\
<title>Color_brewery: test {}</title>\n\
</head>\n\
<body>",
env::args().next().unwrap())?;
writeln!(fh, "<h3>Hue</h3>")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 10, 43, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 30, 13, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 150, 1, "")?;
writeln!(fh, "<h3>Gradients</h3>")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 10, 43, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 30, 13, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 255, 0], 150, 1,
"Best <a href=\"https://youtu.be/XjHzLUnHeM0?t=230\"
>to avoid red and green</a>.")?;
gradient(&mut fh, [0, 0, 0], [255, 255, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 128], [144, 144, 255], 150, 1, "")?;
writeln!(fh, "<h3>Palettes (sequential and diverging)</h3>")?;
for (comment, p) in [("viridis", RGB8::viridis()),
("magma", RGB8::magma()),
("inferno", RGB8::inferno()),
("plasma", RGB8::plasma()),
("viridis", RGB8::viridis()),
("cividis", RGB8::cividis()),
("twilight", RGB8::twilight()),
("turbo", RGB8::turbo())] {
palette(&mut fh, p, 256, 1, comment)?;
}
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
palette(&mut fh, p, 128, 1,
&format!("{} (interpolated)", stringify!($name)))?;
} )*
}}
palette!(ylgn, ylgnbu, gnbu, bugn, pubugn, pubu, bupu, rdpu, purd,
orrd, ylorrd, ylorbr, purples, blues, greens, oranges,
reds, greys,
// Diverging
puor, brbg, prgn, piyg, rdbu, rdgy, rdylbu, spectral, rdylgn);
writeln!(fh, "<h3>Palettes (others)</h3>")?;
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
} )*
}}
palette!(set1, pastel1, set2, pastel2, dark2, set3, paired, accent);
writeln!(fh, "</body>\n\
</html>")?;
Ok(())
}
sourcefn turbo() -> Palette<Self>
fn turbo() -> Palette<Self>
Matplotlib turbo color scheme.
Examples found in repository?
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
fn main() -> Result<(), Err> {
let mut fh = BufWriter::new(File::create("gradient.html")?);
writeln!(fh, "<html>\n\
<head>\n\
<title>Color_brewery: test {}</title>\n\
</head>\n\
<body>",
env::args().next().unwrap())?;
writeln!(fh, "<h3>Hue</h3>")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 10, 43, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 30, 13, "")?;
range(&mut fh, |t| RGB8::HUE.rgb(t), 150, 1, "")?;
writeln!(fh, "<h3>Gradients</h3>")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 10, 43, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 30, 13, "")?;
gradient(&mut fh, [94, 0, 99], [255, 235, 170], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [255, 0, 0], [0, 255, 0], 150, 1,
"Best <a href=\"https://youtu.be/XjHzLUnHeM0?t=230\"
>to avoid red and green</a>.")?;
gradient(&mut fh, [0, 0, 0], [255, 255, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 0], [0, 0, 255], 150, 1, "")?;
gradient(&mut fh, [0, 0, 128], [144, 144, 255], 150, 1, "")?;
writeln!(fh, "<h3>Palettes (sequential and diverging)</h3>")?;
for (comment, p) in [("viridis", RGB8::viridis()),
("magma", RGB8::magma()),
("inferno", RGB8::inferno()),
("plasma", RGB8::plasma()),
("viridis", RGB8::viridis()),
("cividis", RGB8::cividis()),
("twilight", RGB8::twilight()),
("turbo", RGB8::turbo())] {
palette(&mut fh, p, 256, 1, comment)?;
}
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
palette(&mut fh, p, 128, 1,
&format!("{} (interpolated)", stringify!($name)))?;
} )*
}}
palette!(ylgn, ylgnbu, gnbu, bugn, pubugn, pubu, bupu, rdpu, purd,
orrd, ylorrd, ylorbr, purples, blues, greens, oranges,
reds, greys,
// Diverging
puor, brbg, prgn, piyg, rdbu, rdgy, rdylbu, spectral, rdylgn);
writeln!(fh, "<h3>Palettes (others)</h3>")?;
macro_rules! palette { ($($name: ident),*) => {
$( if let Some(p) = RGB8::$name().last() {
let c = format!("{} ({} colors)", stringify!($name), p.len());
table_of_colors(&mut fh, &p.colors(), 40, &c)?;
} )*
}}
palette!(set1, pastel1, set2, pastel2, dark2, set3, paired, accent);
writeln!(fh, "</body>\n\
</html>")?;
Ok(())
}
sourcefn ylgn() -> PaletteIter<Self> ⓘ
fn ylgn() -> PaletteIter<Self> ⓘ
Brewer “Light yellow to dark green” sequential scheme.
sourcefn ylgnbu() -> PaletteIter<Self> ⓘ
fn ylgnbu() -> PaletteIter<Self> ⓘ
Brewer “Light yellow to green to dark blue” sequential scheme.
sourcefn gnbu() -> PaletteIter<Self> ⓘ
fn gnbu() -> PaletteIter<Self> ⓘ
Brewer “Light green to dark blue” sequential scheme.
sourcefn bugn() -> PaletteIter<Self> ⓘ
fn bugn() -> PaletteIter<Self> ⓘ
Brewer “Light blue to dark green” sequential scheme.
sourcefn pubugn() -> PaletteIter<Self> ⓘ
fn pubugn() -> PaletteIter<Self> ⓘ
Brewer “Light purple to blue to dark green” sequential scheme.
sourcefn pubu() -> PaletteIter<Self> ⓘ
fn pubu() -> PaletteIter<Self> ⓘ
Brewer “Light purple to dark blue” sequential scheme.
sourcefn bupu() -> PaletteIter<Self> ⓘ
fn bupu() -> PaletteIter<Self> ⓘ
Brewer “Light blue to dark purple” sequential scheme.
sourcefn rdpu() -> PaletteIter<Self> ⓘ
fn rdpu() -> PaletteIter<Self> ⓘ
Brewer “Light red to dark purple” sequential scheme.
sourcefn purd() -> PaletteIter<Self> ⓘ
fn purd() -> PaletteIter<Self> ⓘ
Brewer “Light purple to dark red” sequential scheme.
sourcefn orrd() -> PaletteIter<Self> ⓘ
fn orrd() -> PaletteIter<Self> ⓘ
Brewer “Light orange to dark red” sequential scheme.
sourcefn ylorrd() -> PaletteIter<Self> ⓘ
fn ylorrd() -> PaletteIter<Self> ⓘ
Brewer “Light yellow to orange to dark red” sequential scheme.
sourcefn ylorbr() -> PaletteIter<Self> ⓘ
fn ylorbr() -> PaletteIter<Self> ⓘ
Brewer “Light yellow to orange to dark brown” sequential scheme.
sourcefn purples() -> PaletteIter<Self> ⓘ
fn purples() -> PaletteIter<Self> ⓘ
Brewer “Light to dark purple” sequential scheme.
sourcefn blues() -> PaletteIter<Self> ⓘ
fn blues() -> PaletteIter<Self> ⓘ
Brewer “Light to dark blue” sequential scheme.
sourcefn greens() -> PaletteIter<Self> ⓘ
fn greens() -> PaletteIter<Self> ⓘ
Brewer “Light to dark green” sequential scheme.
sourcefn oranges() -> PaletteIter<Self> ⓘ
fn oranges() -> PaletteIter<Self> ⓘ
Brewer “Light to dark orange” sequential scheme.
sourcefn reds() -> PaletteIter<Self> ⓘ
fn reds() -> PaletteIter<Self> ⓘ
Brewer “Light to dark red” sequential scheme.
sourcefn greys() -> PaletteIter<Self> ⓘ
fn greys() -> PaletteIter<Self> ⓘ
Brewer “Light to dark gray” sequential scheme.
sourcefn puor() -> PaletteIter<Self> ⓘ
fn puor() -> PaletteIter<Self> ⓘ
Brewer “Dark orange to light to dark purple” diverging scheme
sourcefn brbg() -> PaletteIter<Self> ⓘ
fn brbg() -> PaletteIter<Self> ⓘ
Brewer “Dark brown to light to dark blue-green” diverging scheme
sourcefn prgn() -> PaletteIter<Self> ⓘ
fn prgn() -> PaletteIter<Self> ⓘ
Brewer “Dark reddish-purple to light to dark green” diverging scheme
sourcefn piyg() -> PaletteIter<Self> ⓘ
fn piyg() -> PaletteIter<Self> ⓘ
Brewer “Dark magenta to light to dark yellow-green” diverging scheme
sourcefn rdbu() -> PaletteIter<Self> ⓘ
fn rdbu() -> PaletteIter<Self> ⓘ
Brewer “Dark red to light to dark blue” diverging scheme.
sourcefn rdgy() -> PaletteIter<Self> ⓘ
fn rdgy() -> PaletteIter<Self> ⓘ
Brewer “Dark red to light to dark grey” diverging scheme.
sourcefn rdylbu() -> PaletteIter<Self> ⓘ
fn rdylbu() -> PaletteIter<Self> ⓘ
Brewer “Dark red to light yelow to dark blue” diverging scheme.
sourcefn spectral() -> PaletteIter<Self> ⓘ
fn spectral() -> PaletteIter<Self> ⓘ
Brewer “Dark red, orange, light yellow, green, dark blue” diverging scheme.
sourcefn rdylgn() -> PaletteIter<Self> ⓘ
fn rdylgn() -> PaletteIter<Self> ⓘ
Brewer “Dark red, orange, light yellow, yellow-green, dark green” diverging scheme.
sourcefn set1() -> PaletteIter<Self> ⓘ
fn set1() -> PaletteIter<Self> ⓘ
Brewer qualitative scheme: includes bold, readily named, basic colors (such as red, green, blue).
sourcefn pastel1() -> PaletteIter<Self> ⓘ
fn pastel1() -> PaletteIter<Self> ⓘ
Brewer qualitative scheme: Lighter version of Self::set1
.
sourcefn set2() -> PaletteIter<Self> ⓘ
fn set2() -> PaletteIter<Self> ⓘ
Brewer qualitative scheme: Includes mostly a mixture colors (such as blue-green, red-orange).
sourcefn pastel2() -> PaletteIter<Self> ⓘ
fn pastel2() -> PaletteIter<Self> ⓘ
Brewer qualitative scheme: Lighter version of Self::set2
.
sourcefn dark2() -> PaletteIter<Self> ⓘ
fn dark2() -> PaletteIter<Self> ⓘ
Brewer qualitative scheme: Darker version of Self::set2
.
sourcefn set3() -> PaletteIter<Self> ⓘ
fn set3() -> PaletteIter<Self> ⓘ
Brewer qualitative scheme: Medium saturation set with more
lightness variation and more classes than Self::set1
and
Self::set2
.
sourcefn paired() -> PaletteIter<Self> ⓘ
fn paired() -> PaletteIter<Self> ⓘ
Brewer qualitative scheme: Light/dark paris for namable hues.
sourcefn accent() -> PaletteIter<Self> ⓘ
fn accent() -> PaletteIter<Self> ⓘ
Brewer qualitative scheme: Include lightness and saturation extremes to accent small or important areas.
sourcefn to_gray(&self) -> Self
fn to_gray(&self) -> Self
Convert the color to grayscale.
Examples found in repository?
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn table_of_colors(fh: &mut impl Write, colors: &Vec<RGB8>,
width: u32, comment: &str) -> Result<(), Err> {
writeln!(fh, "<table style=\"border: 0px; border-spacing: 0px\"><tr>")?;
for &c in colors {
writeln!(fh, " <td style=\"width: {width}px; height: 30px; \
background-color: {}\"></td>",
css_string(c))?;
}
writeln!(fh, "<td rowspan=\"2\" style=\"padding-left: 7px\">\
{comment}</td></tr><tr>")?;
for &c in colors {
let c = c.to_gray();
writeln!(fh, " <td style=\"width: {width}px; height: 12px; \
background-color: {}\"></td>",
css_string(c))?;
}
writeln!(fh, "</tr></table><br/>")?;
Ok(())
}