colorgrad-rs
Rust color scales library for charts, maps, data-visualization and creative coding.
Index
Usage
Add colorgrad to your Cargo.toml
[]
= "0.3.0"
Custom Gradient
Basic
let g = new.build?;

Custom Colors
use Color;
let g = new
.colors
.build?;

Using Web Color Format
.html_colors() method accepts named colors, hexadecimal (#rgb, #rgba, #rrggbb, #rrggbbaa), rgb(), rgba(), hsl(), hsla(), hwb(), and hsv().
let g = new
.html_colors
.build?;

let g = new
.html_colors
.build?;

let g = new
.html_colors
.build?;

Domain & Color Position
Default domain is [0..1].
let g = new
.html_colors
.build?;
assert_eq!;

Set the domain to [0..100].
let g = new
.html_colors
.domain
.build?;
assert_eq!;

Set the domain to [-1..1].
let g = new
.html_colors
.domain
.build?;
assert_eq!;

Set exact position for each color. The domain is [0..1].
let g = new
.html_colors
.domain
.build?;
assert_eq!;

Set exact position for each color. The domain is [15..80].
let g = new
.html_colors
.domain
.build?;
assert_eq!;

Blending Mode
let g = new
.html_colors
.mode
.build?;

Preset Gradients
All preset gradients are in the domain [0..1]. Uniform B-splines is used to interpolate the colors.

Diverging
colorgrad::br_bg()

colorgrad::pr_gn()

colorgrad::pi_yg()

colorgrad::pu_or()

colorgrad::rd_bu()

colorgrad::rd_gy()

colorgrad::rd_yl_bu()

colorgrad::rd_yl_gn()

colorgrad::spectral()

Sequential (Single Hue)
colorgrad::blues()

colorgrad::greens()

colorgrad::greys()

colorgrad::oranges()

colorgrad::purples()

colorgrad::reds()

Sequential (Multi-Hue)
colorgrad::turbo()

colorgrad::viridis()

colorgrad::inferno()

colorgrad::magma()

colorgrad::plasma()

colorgrad::cividis()

colorgrad::warm()

colorgrad::cool()

colorgrad::cubehelix_default()

colorgrad::bu_gn()

colorgrad::bu_pu()

colorgrad::gn_bu()

colorgrad::or_rd()

colorgrad::pu_bu_gn()

colorgrad::pu_bu()

colorgrad::pu_rd()

colorgrad::rd_pu()

colorgrad::yl_gn_bu()

colorgrad::yl_gn()

colorgrad::yl_or_br()

colorgrad::yl_or_rd()

Cyclical
colorgrad::rainbow()

colorgrad::sinebow()

Using the Gradient
Get the domain
let grad = rainbow;
assert_eq!;
Get single color at certain position
let grad = rainbow;
assert_eq!;
assert_eq!;
assert_eq!;
Get n colors evenly spaced across gradient
let grad = rainbow;
for c in grad.colors
Output:
#6e40aa
#c83dac
#ff5375
#ff8c38
#c9d33a
#7cf659
#5dea8d
#48b8d0
#4775de
#6e40aa
Hard-Edged Gradient
Convert gradient to hard-edged gradient with 11 segments and 0 smoothness.
let g = rainbow.sharp;

This is the effect of different smoothness.

Examples
Gradient Image
//extern crate colorgrad;
//extern crate image;
use Error;
Example output:

Colored Noise
//extern crate colorgrad;
//extern crate image;
//extern crate noise;
use NoiseFn;
// Map value which is in range [a, b] to range [c, d]
Example output:

Inspirations
Links
- colorgrad - Go version of this library
- Color Blindness Simulator
- Visual System Simulator