colorgrad-rs
Rust color scales library for data visualization, charts, games, maps, generative art and others.
Support This Project
Index
- Custom Gradient
- Preset Gradients
- Parsing GIMP Gradient
- Using the Gradient
- Examples
- Similar Projects
- Projects using
colorgrad
Usage
Add this to your Cargo.toml
= "0.5.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?;

Interpolation Mode
let g = new
.html_colors
.interpolation
.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()

Parsing GIMP Gradient
use Color;
use File;
use BufReader;
let input = open?;
let buf = new;
let fg = from_rgb;
let bg = from_rgb;
let = parse_ggr?;
assert_eq!;

Using the Gradient
Get the domain
let grad = rainbow;
assert_eq!;
Get single color at certain position
let grad = blues;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
The difference of at(), repeat_at() and reflect_at().

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
Example output:

Colored Noise
use NoiseFn;
// Map t which is in range [a, b] to range [c, d]
Example output:

Default Feature
- named-colors: Enables parsing from named colors. Requires
phf. Can be disabled usingdefault-features = false.
Similar Projects
- colorgrad (Go version of this library)
- colorous (Rust)
- chroma.js (Javascript)
- d3-scale-chromatic (Javascript)
Projects using colorgrad
- WezTerm - A GPU-accelerated cross-platform terminal emulator and multiplexer
- bytehound - A memory profiler for Linux
- rust-fractal - Mandelbrot fractal visualizer
- eruption - A Linux user-mode input and LED driver for keyboards, mice and other devices
- lcat -
lolcatclone - gradient - A command line tool for playing with color gradient