1 //! # Colorous 2 //! 3 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/viridis.png" width="100%" height="20" alt="viridis"> 4 //! <br><br> 5 //! 6 //! This crate provides a collection of sequential, diverging and categorical 7 //! color schemes ported from [d3-scale-chromatic]. Each color scheme may be 8 //! sampled using either a rational index `i/n` or a continuous float `0 ≤ t ≤ 9 //! 1`. 10 //! 11 //! - `pub fn eval_rational(&self, i: usize, n: usize) -> Color` 12 //! - `pub fn eval_continuous(&self, t: f64) -> Color` 13 //! 14 //! [d3-scale-chromatic]: https://github.com/d3/d3-scale-chromatic 15 //! 16 //! <br> 17 //! 18 //! ## Example 19 //! 20 //! ``` 21 //! let gradient = colorous::VIRIDIS; 22 //! for i in 0..100 { 23 //! println!("{:x}", gradient.eval_rational(i, 100)); 24 //! } 25 //! ``` 26 //! 27 //! <br><br> 28 //! 29 //! ## Sequential (multi-hue) 30 //! 31 //! <a href="#Turbo" name="Turbo">#</a> colorous::<b>TURBO</b> 32 //! 33 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/turbo.png" width="100%" height="40" alt="turbo"> 34 //! 35 //! The “turbo” color scheme by [Anton Mikhailov](https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html). 36 //! 37 //! <a href="#Viridis" name="Viridis">#</a> colorous::<b>VIRIDIS</b> 38 //! 39 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/viridis.png" width="100%" height="40" alt="viridis"> 40 //! 41 //! The “viridis” perceptually-uniform color scheme designed by [van der Walt, Smith and Firing](https://bids.github.io/colormap/) for matplotlib. 42 //! 43 //! <a href="#Inferno" name="Inferno">#</a> colorous::<b>INFERNO</b> 44 //! 45 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/inferno.png" width="100%" height="40" alt="inferno"> 46 //! 47 //! The “inferno” perceptually-uniform color scheme designed by [van der Walt and Smith](https://bids.github.io/colormap/) for matplotlib. 48 //! 49 //! <a href="#Magma" name="Magma">#</a> colorous::<b>MAGMA</b> 50 //! 51 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/magma.png" width="100%" height="40" alt="magma"> 52 //! 53 //! The “magma” perceptually-uniform color scheme designed by [van der Walt and Smith](https://bids.github.io/colormap/) for matplotlib. 54 //! 55 //! <a href="#Plasma" name="Plasma">#</a> colorous::<b>PLASMA</b> 56 //! 57 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/plasma.png" width="100%" height="40" alt="plasma"> 58 //! 59 //! The “plasma” perceptually-uniform color scheme designed by [van der Walt and Smith](https://bids.github.io/colormap/) for matplotlib. 60 //! 61 //! <a href="#Cividis" name="Cividis">#</a> colorous::<b>CIVIDIS</b> 62 //! 63 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/cividis.png" width="100%" height="40" alt="cividis"> 64 //! 65 //! The “cividis” color vision deficiency-optimized color scheme designed by [Nuñez, Anderton, and Renslow](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0199239). 66 //! 67 //! <a href="#Warm" name="Warm">#</a> colorous::<b>WARM</b> 68 //! 69 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/warm.png" width="100%" height="40" alt="warm"> 70 //! 71 //! A 180° rotation of [Niccoli’s perceptual rainbow](https://mycarta.wordpress.com/2013/02/21/perceptual-rainbow-palette-the-method/). 72 //! 73 //! <a href="#Cool" name="Cool">#</a> colorous::<b>COOL</b> 74 //! 75 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/cool.png" width="100%" height="40" alt="cool"> 76 //! 77 //! [Niccoli’s perceptual rainbow](https://mycarta.wordpress.com/2013/02/21/perceptual-rainbow-palette-the-method/). 78 //! 79 //! <a href="#CubehelixDefault" name="CubehelixDefault">#</a> colorous::<b>CUBEHELIX</b> 80 //! 81 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/cubehelix.png" width="100%" height="40" alt="cubehelix"> 82 //! 83 //! [Green’s default Cubehelix](https://www.mrao.cam.ac.uk/~dag/CUBEHELIX/). 84 //! 85 //! <a href="#BuGn" name="BuGn">#</a> colorous::<b>BLUE_GREEN</b> 86 //! 87 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/BuGn.png" width="100%" height="40" alt="BuGn"> 88 //! 89 //! <a href="#BuPu" name="BuPu">#</a> colorous::<b>BLUE_PURPLE</b> 90 //! 91 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/BuPu.png" width="100%" height="40" alt="BuPu"> 92 //! 93 //! <a href="#GnBu" name="GnBu">#</a> colorous::<b>GREEN_BLUE</b> 94 //! 95 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/GnBu.png" width="100%" height="40" alt="GnBu"> 96 //! 97 //! <a href="#OrRd" name="OrRd">#</a> colorous::<b>ORANGE_RED</b> 98 //! 99 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/OrRd.png" width="100%" height="40" alt="OrRd"> 100 //! 101 //! <a href="#PuBuGn" name="PuBuGn">#</a> colorous::<b>PURPLE_BLUE_GREEN</b> 102 //! 103 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/PuBuGn.png" width="100%" height="40" alt="PuBuGn"> 104 //! 105 //! <a href="#PuBu" name="PuBu">#</a> colorous::<b>PURPLE_BLUE</b> 106 //! 107 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/PuBu.png" width="100%" height="40" alt="PuBu"> 108 //! 109 //! <a href="#PuRd" name="PuRd">#</a> colorous::<b>PURPLE_RED</b> 110 //! 111 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/PuRd.png" width="100%" height="40" alt="PuRd"> 112 //! 113 //! <a href="#RdPu" name="RdPu">#</a> colorous::<b>RED_PURPLE</b> 114 //! 115 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/RdPu.png" width="100%" height="40" alt="RdPu"> 116 //! 117 //! <a href="#YlGnBu" name="YlGnBu">#</a> colorous::<b>YELLOW_GREEN_BLUE</b> 118 //! 119 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/YlGnBu.png" width="100%" height="40" alt="YlGnBu"> 120 //! 121 //! <a href="#YlGn" name="YlGn">#</a> colorous::<b>YELLOW_GREEN</b> 122 //! 123 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/YlGn.png" width="100%" height="40" alt="YlGn"> 124 //! 125 //! <a href="#YlOrBr" name="YlOrBr">#</a> colorous::<b>YELLOW_ORANGE_BROWN</b> 126 //! 127 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/YlOrBr.png" width="100%" height="40" alt="YlOrBr"> 128 //! 129 //! <a href="#YlOrRd" name="YlOrRd">#</a> colorous::<b>YELLOW_ORANGE_RED</b> 130 //! 131 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/YlOrRd.png" width="100%" height="40" alt="YlOrRd"> 132 //! 133 //! <br><br> 134 //! 135 //! ## Sequential (single-hue) 136 //! 137 //! <a href="#Blues" name="Blues">#</a> colorous::<b>BLUES</b> 138 //! 139 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Blues.png" width="100%" height="40" alt="Blues"> 140 //! 141 //! <a href="#Greens" name="Greens">#</a> colorous::<b>GREENS</b> 142 //! 143 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Greens.png" width="100%" height="40" alt="Greens"> 144 //! 145 //! <a href="#Greys" name="Greys">#</a> colorous::<b>GREYS</b> 146 //! 147 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Greys.png" width="100%" height="40" alt="Greys"> 148 //! 149 //! <a href="#Oranges" name="Oranges">#</a> colorous::<b>ORANGES</b> 150 //! 151 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Oranges.png" width="100%" height="40" alt="Oranges"> 152 //! 153 //! <a href="#Purples" name="Purples">#</a> colorous::<b>PURPLES</b> 154 //! 155 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Purples.png" width="100%" height="40" alt="Purples"> 156 //! 157 //! <a href="#Reds" name="Reds">#</a> colorous::<b>REDS</b> 158 //! 159 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Reds.png" width="100%" height="40" alt="Reds"> 160 //! 161 //! <br><br> 162 //! 163 //! ## Diverging 164 //! 165 //! <a href="#BrBG" name="BrBG">#</a> colorous::<b>BROWN_GREEN</b> 166 //! 167 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/BrBG.png" width="100%" height="40" alt="BrBG"> 168 //! 169 //! <a href="#PRGn" name="PRGn">#</a> colorous::<b>PURPLE_GREEN</b> 170 //! 171 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/PRGn.png" width="100%" height="40" alt="PRGn"> 172 //! 173 //! <a href="#PiYG" name="PiYG">#</a> colorous::<b>PINK_GREEN</b> 174 //! 175 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/PiYG.png" width="100%" height="40" alt="PiYG"> 176 //! 177 //! <a href="#PuOr" name="PuOr">#</a> colorous::<b>PURPLE_ORANGE</b> 178 //! 179 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/PuOr.png" width="100%" height="40" alt="PuOr"> 180 //! 181 //! <a href="#RdBu" name="RdBu">#</a> colorous::<b>RED_BLUE</b> 182 //! 183 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/RdBu.png" width="100%" height="40" alt="RdBu"> 184 //! 185 //! <a href="#RdGy" name="RdGy">#</a> colorous::<b>RED_GREY</b> 186 //! 187 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/RdGy.png" width="100%" height="40" alt="RdGy"> 188 //! 189 //! <a href="#RdYlBu" name="RdYlBu">#</a> colorous::<b>RED_YELLOW_BLUE</b> 190 //! 191 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/RdYlBu.png" width="100%" height="40" alt="RdYlBu"> 192 //! 193 //! <a href="#RdYlGn" name="RdYlGn">#</a> colorous::<b>RED_YELLOW_GREEN</b> 194 //! 195 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/RdYlGn.png" width="100%" height="40" alt="RdYlGn"> 196 //! 197 //! <a href="#Spectral" name="Spectral">#</a> colorous::<b>SPECTRAL</b> 198 //! 199 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Spectral.png" width="100%" height="40" alt="Spectral"> 200 //! 201 //! <br><br> 202 //! 203 //! ## Cyclical 204 //! 205 //! <a href="#Rainbow" name="Rainbow">#</a> colorous::<b>RAINBOW</b> 206 //! 207 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/rainbow.png" width="100%" height="40" alt="rainbow"> 208 //! 209 //! The cyclical [less-angry rainbow](http://bl.ocks.org/mbostock/310c99e53880faec2434) color scheme. 210 //! 211 //! <a href="#Sinebow" name="Sinebow">#</a> colorous::<b>SINEBOW</b> 212 //! 213 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/sinebow.png" width="100%" height="40" alt="sinebow"> 214 //! 215 //! The “sinebow” color scheme by [Jim Bumgardner](https://krazydad.com/tutorials/makecolors.php) and [Charlie Loyd](http://basecase.org/env/on-rainbows). 216 //! 217 //! <br> 218 //! 219 //! ## Categorical 220 //! 221 //! Categorical color schemes are represented simply as an array `[Color; N]`. 222 //! 223 //! <a href="#Category10" name="Category10">#</a> colorous::<b>CATEGORY10</b> 224 //! 225 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/category10.png" width="100%" height="40" alt="category10"> 226 //! 227 //! <a href="#Accent" name="Accent">#</a> colorous::<b>ACCENT</b> 228 //! 229 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Accent.png" width="100%" height="40" alt="Accent"> 230 //! 231 //! <a href="#Dark2" name="Dark2">#</a> colorous::<b>DARK2</b> 232 //! 233 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Dark2.png" width="100%" height="40" alt="Dark2"> 234 //! 235 //! <a href="#Paired" name="Paired">#</a> colorous::<b>PAIRED</b> 236 //! 237 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Paired.png" width="100%" height="40" alt="Paired"> 238 //! 239 //! <a href="#Pastel1" name="Pastel1">#</a> colorous::<b>PASTEL1</b> 240 //! 241 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Pastel1.png" width="100%" height="40" alt="Pastel1"> 242 //! 243 //! <a href="#Pastel2" name="Pastel2">#</a> colorous::<b>PASTEL2</b> 244 //! 245 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Pastel2.png" width="100%" height="40" alt="Pastel2"> 246 //! 247 //! <a href="#Set1" name="Set1">#</a> colorous::<b>SET1</b> 248 //! 249 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Set1.png" width="100%" height="40" alt="Set1"> 250 //! 251 //! <a href="#Set2" name="Set2">#</a> colorous::<b>SET2</b> 252 //! 253 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Set2.png" width="100%" height="40" alt="Set2"> 254 //! 255 //! <a href="#Set3" name="Set3">#</a> colorous::<b>SET3</b> 256 //! 257 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Set3.png" width="100%" height="40" alt="Set3"> 258 //! 259 //! <a href="#Tableau10" name="Tableau10">#</a> colorous::<b>TABLEAU10</b> 260 //! 261 //! <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Tableau10.png" width="100%" height="40" alt="Tableau10"> 262 //! 263 //! Ten categorical colors authored by Tableau as part of [Tableau 10](https://www.tableau.com/about/blog/2016/7/colors-upgrade-tableau-10-56782). 264 265 #![doc(html_root_url = "https://docs.rs/colorous/1.0.1")] 266 #![warn(clippy::pedantic)] 267 #![allow( 268 clippy::cast_lossless, 269 clippy::cast_possible_truncation, 270 clippy::cast_precision_loss, 271 clippy::cast_sign_loss, 272 clippy::doc_markdown, 273 clippy::must_use_candidate, 274 clippy::shadow_unrelated, 275 clippy::trivially_copy_pass_by_ref, 276 clippy::unreadable_literal 277 )] 278 279 #[macro_use] 280 mod macros; 281 282 mod categorical; 283 mod color; 284 mod cubehelix; 285 mod cyclical; 286 mod diverging; 287 mod gradient; 288 mod interpolate; 289 mod sequential; 290 mod sequential_multi; 291 mod sequential_single; 292 293 pub use crate::categorical::{ 294 ACCENT, CATEGORY10, DARK2, PAIRED, PASTEL1, PASTEL2, SET1, SET2, SET3, TABLEAU10, 295 }; 296 pub use crate::color::Color; 297 pub use crate::cyclical::{RAINBOW, SINEBOW}; 298 pub use crate::diverging::{ 299 BROWN_GREEN, PINK_GREEN, PURPLE_GREEN, PURPLE_ORANGE, RED_BLUE, RED_GREY, RED_YELLOW_BLUE, 300 RED_YELLOW_GREEN, SPECTRAL, 301 }; 302 pub use crate::gradient::Gradient; 303 pub use crate::sequential_multi::{ 304 BLUE_GREEN, BLUE_PURPLE, CIVIDIS, COOL, CUBEHELIX, GREEN_BLUE, INFERNO, MAGMA, ORANGE_RED, 305 PLASMA, PURPLE_BLUE, PURPLE_BLUE_GREEN, PURPLE_RED, RED_PURPLE, TURBO, VIRIDIS, WARM, 306 YELLOW_GREEN, YELLOW_GREEN_BLUE, YELLOW_ORANGE_BROWN, YELLOW_ORANGE_RED, 307 }; 308 pub use crate::sequential_single::{BLUES, GREENS, GREYS, ORANGES, PURPLES, REDS}; 309