All Projects → mazznoer → Colorgrad Rs

mazznoer / Colorgrad Rs

Licence: other
Rust color scales library

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Colorgrad Rs

Colorwanted
Screen color picker for Windows (Windows 上的屏幕取色器)
Stars: ✭ 105 (-19.23%)
Mutual labels:  color
Colors.jl
Color manipulation utilities for Julia
Stars: ✭ 114 (-12.31%)
Mutual labels:  color
Yowish.vim
A dark & yellowish vim colorscheme
Stars: ✭ 125 (-3.85%)
Mutual labels:  color
Monolog Colored Line Formatter
Colored/ANSI Line Formatter for Monolog
Stars: ✭ 108 (-16.92%)
Mutual labels:  color
Console Logging
Better, prettier commandline logging for Python--with colors! 👻
Stars: ✭ 111 (-14.62%)
Mutual labels:  color
Box Cli Maker
Make Highly Customized Boxes for your CLI
Stars: ✭ 115 (-11.54%)
Mutual labels:  color
Wb srgb
White balance camera-rendered sRGB images (CVPR 2019) [Matlab & Python]
Stars: ✭ 101 (-22.31%)
Mutual labels:  color
Sty
String styling for your terminal.
Stars: ✭ 129 (-0.77%)
Mutual labels:  color
Dainty Vs
Dainty for Visual Studio – A color theme generator using Lab color space
Stars: ✭ 115 (-11.54%)
Mutual labels:  color
Calico
cat, but for colors 😼
Stars: ✭ 122 (-6.15%)
Mutual labels:  color
Chalk Animation
🎬 Colorful animations in terminal output
Stars: ✭ 1,489 (+1045.38%)
Mutual labels:  color
Magit Delta
Use delta (https://github.com/dandavison/delta) when viewing diffs in Magit
Stars: ✭ 109 (-16.15%)
Mutual labels:  color
Tinycolormap
A header-only, single-file library for colormaps written in C++11
Stars: ✭ 119 (-8.46%)
Mutual labels:  color
Smartmaterialspinner
The powerful android spinner library for your application
Stars: ✭ 108 (-16.92%)
Mutual labels:  color
Kite
🪁 Android Resources Wrapper Library
Stars: ✭ 127 (-2.31%)
Mutual labels:  color
Iceberg.vim
🇦🇶 Bluish color scheme for Vim and Neovim
Stars: ✭ 1,636 (+1158.46%)
Mutual labels:  color
Zoya
Truly highly composable logging utility
Stars: ✭ 116 (-10.77%)
Mutual labels:  color
Nord Vim
An arctic, north-bluish clean and elegant Vim theme.
Stars: ✭ 1,987 (+1428.46%)
Mutual labels:  color
Colour Demosaicing
CFA (Colour Filter Array) Demosaicing Algorithms for Python
Stars: ✭ 127 (-2.31%)
Mutual labels:  color
Colorspacious
A powerful, accurate, and easy-to-use Python library for doing colorspace conversions
Stars: ✭ 120 (-7.69%)
Mutual labels:  color

colorgrad-rs

crates.io Documentation Build Status Build Status codecov

Rust color scales library for data visualization, charts, games, maps, generative art and others.

Support This Project

Donate

Index

Usage

Add this to your Cargo.toml

colorgrad = "0.3.0"

Custom Gradient

Basic

let g = colorgrad::CustomGradient::new().build()?;

img

Custom Colors

use colorgrad::Color;

let g = colorgrad::CustomGradient::new()
    .colors(&[
        Color::from_rgb_u8(0, 206, 209),
        Color::from_rgb_u8(255, 105, 180),
        Color::from_rgb(0.274, 0.5, 0.7),
        Color::from_hsv(50., 1., 1.),
        Color::from_hsv(348., 0.9, 0.8),
    ])
    .build()?;

img

Using Web Color Format

.html_colors() method accepts named colors, hexadecimal (#rgb, #rgba, #rrggbb, #rrggbbaa), rgb(), rgba(), hsl(), hsla(), hwb(), and hsv().

let g = colorgrad::CustomGradient::new()
    .html_colors(&["#C41189", "#00BFFF", "#FFD700"])
    .build()?;

img

let g = colorgrad::CustomGradient::new()
    .html_colors(&["gold", "hotpink", "darkturquoise"])
    .build()?;

img

let g = colorgrad::CustomGradient::new()
    .html_colors(&["rgb(125,110,221)", "rgb(90%,45%,97%)", "hsl(229,79%,85%)"])
    .build()?;

img

Domain & Color Position

Default domain is [0..1].

let g = colorgrad::CustomGradient::new()
    .html_colors(&["deeppink", "gold", "seagreen"])
    .build()?;

assert_eq!(g.domain(), (0., 1.));

img

Set the domain to [0..100].

let g = colorgrad::CustomGradient::new()
    .html_colors(&["deeppink", "gold", "seagreen"])
    .domain(&[0., 100.])
    .build()?;

assert_eq!(g.domain(), (0., 100.));

img

Set the domain to [-1..1].

let g = colorgrad::CustomGradient::new()
    .html_colors(&["deeppink", "gold", "seagreen"])
    .domain(&[-1., 1.])
    .build()?;

assert_eq!(g.domain(), (-1., 1.));

img

Set exact position for each color. The domain is [0..1].

let g = colorgrad::CustomGradient::new()
    .html_colors(&["deeppink", "gold", "seagreen"])
    .domain(&[0., 0.7, 1.])
    .build()?;

assert_eq!(g.domain(), (0., 1.));

img

Set exact position for each color. The domain is [15..80].

let g = colorgrad::CustomGradient::new()
    .html_colors(&["deeppink", "gold", "seagreen"])
    .domain(&[15., 30., 80.])
    .build()?;

assert_eq!(g.domain(), (15., 80.));

img

Blending Mode

let g = colorgrad::CustomGradient::new()
    .html_colors(&["#FFF", "#00F"])
    .mode(colorgrad::BlendMode::Rgb)
    .build()?;

Blending Modes

Interpolation Mode

let g = colorgrad::CustomGradient::new()
    .html_colors(&["#C41189", "#00BFFF", "#FFD700"])
    .interpolation(colorgrad::Interpolation::Linear)
    .build()?;

Interpolation Modes

Preset Gradients

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

img

Diverging

colorgrad::br_bg() img

colorgrad::pr_gn() img

colorgrad::pi_yg() img

colorgrad::pu_or() img

colorgrad::rd_bu() img

colorgrad::rd_gy() img

colorgrad::rd_yl_bu() img

colorgrad::rd_yl_gn() img

colorgrad::spectral() img

Sequential (Single Hue)

colorgrad::blues() img

colorgrad::greens() img

colorgrad::greys() img

colorgrad::oranges() img

colorgrad::purples() img

colorgrad::reds() img

Sequential (Multi-Hue)

colorgrad::turbo() img

colorgrad::viridis() img

colorgrad::inferno() img

colorgrad::magma() img

colorgrad::plasma() img

colorgrad::cividis() img

colorgrad::warm() img

colorgrad::cool() img

colorgrad::cubehelix_default() img

colorgrad::bu_gn() img

colorgrad::bu_pu() img

colorgrad::gn_bu() img

colorgrad::or_rd() img

colorgrad::pu_bu_gn() img

colorgrad::pu_bu() img

colorgrad::pu_rd() img

colorgrad::rd_pu() img

colorgrad::yl_gn_bu() img

colorgrad::yl_gn() img

colorgrad::yl_or_br() img

colorgrad::yl_or_rd() img

Cyclical

colorgrad::rainbow() img

colorgrad::sinebow() img

Using the Gradient

Get the domain

let grad = colorgrad::rainbow();

assert_eq!(grad.domain(), (0., 1.));

Get single color at certain position

let grad = colorgrad::blues();

assert_eq!(grad.at(0.0).rgba_u8(), (247, 251, 255, 255));
assert_eq!(grad.at(0.5).rgba_u8(), (109, 174, 213, 255));
assert_eq!(grad.at(1.0).rgba_u8(), (8,   48,  107, 255));

assert_eq!(grad.at(0.3).rgba_u8(), grad.repeat_at(0.3).rgba_u8());
assert_eq!(grad.at(0.3).rgba_u8(), grad.reflect_at(0.3).rgba_u8());

assert_eq!(grad.at(0.7).rgba_u8(), grad.repeat_at(0.7).rgba_u8());
assert_eq!(grad.at(0.7).rgba_u8(), grad.reflect_at(0.7).rgba_u8());

The difference of at(), repeat_at() and reflect_at().

Spread Modes

Get n colors evenly spaced across gradient

let grad = colorgrad::rainbow();

for c in grad.colors(10) {
    println!("{}", c.to_hex_string());
}

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 = colorgrad::rainbow().sharp(11, 0.);

img

This is the effect of different smoothness.

img

Examples

Gradient Image

use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let grad = colorgrad::CustomGradient::new()
        .html_colors(&["deeppink", "gold", "seagreen"])
        .build()?;

    let w = 1500;
    let h = 70;
    let fw = w as f64;

    let mut imgbuf = image::ImageBuffer::new(w, h);

    for (x, _, pixel) in imgbuf.enumerate_pixels_mut() {
        let (r, g, b, _) = grad.at(x as f64 / fw).rgba_u8();
        *pixel = image::Rgb([r, g, b]);
    }

    imgbuf.save("gradient.png")?;
    Ok(())
}

Example output:

img

Colored Noise

use noise::NoiseFn;

fn main() {
    let w = 600;
    let h = 350;
    let scale = 0.015;

    let grad = colorgrad::rainbow().sharp(5, 0.15);
    let ns = noise::OpenSimplex::new();
    let mut imgbuf = image::ImageBuffer::new(w, h);

    for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
        let t = ns.get([x as f64 * scale, y as f64 * scale]);
        let (r, g, b, _) = grad.at(remap(t, -0.5, 0.5, 0.0, 1.0)).rgba_u8();
        *pixel = image::Rgb([r, g, b]);
    }
    imgbuf.save("noise.png").unwrap();
}

// Map t which is in range [a, b] to range [c, d]
fn remap(t: f64, a: f64, b: f64, c: f64, d: f64) -> f64 {
    (t - a) * ((d - c) / (b - a)) + c
}

Example output:

img

Inspirations

Links

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].