2个不稳定版本

0.2.0 2020年10月8日
0.1.0 2017年8月11日

#24 in #palette

Apache-2.0

230KB
9K SLoC

colorbrewer-rs

Build Status

从著名的 ColorBrewer 调色板中获取颜色(使用rgb crate描述)。这些颜色规范和设计由Cynthia Brewer开发(http://colorbrewer2.org/)。

用法

use colorbrewer::{Palette, get_ramp};

// Use an existing palette from the `Palette` Enum and the wanted number of colors:
let ramp_orange = get_color_ramp(Palette::Oranges, 3);
assert_eq!(
  ramp_orange,
  Some(
    vec![
      rgb::RGB { r: 254, g: 230, b: 206},
      rgb::RGB { r: 253, g: 174, b: 107},
      rgb::RGB { r: 230, g: 85, b: 13},
    ]
  ));

// Or match the name of one palette with the corresponding Enum variant
// using the 'parse' method of a string:
let blue_pal: Palette = "Blues".parse().unwrap();
let ramp = get_color_ramp(blue_pal, 5);

// `None` is returned if the number is invalid:
let ramp = get_color_ramp(Palette::Pastel2, 35);
assert_eq!(ramp, None);

许可协议

根据Apache License,版本2.0许可。

致谢

  • 毫不掩饰地从https://github.com/saikocat/colorbrewercolorbrewer JS Object复制/粘贴/替换等,将其转换为嵌套的rust match,并在函数中包装。
  • rustfmt主要完成了剩余的工作。

依赖

~86KB