#color #random #hsl #rgb #rgba

random_color

Rust crate for generating random attractive colors

10 unstable releases (4 breaking)

0.8.0 Dec 18, 2023
0.6.1 Sep 29, 2021
0.5.1 Mar 28, 2021
0.5.0 Oct 3, 2020
0.4.1 Nov 14, 2017

#68 in Images

Download history 463/week @ 2023-12-23 860/week @ 2023-12-30 1272/week @ 2024-01-06 929/week @ 2024-01-13 1212/week @ 2024-01-20 1034/week @ 2024-01-27 1445/week @ 2024-02-03 1833/week @ 2024-02-10 1630/week @ 2024-02-17 1994/week @ 2024-02-24 2470/week @ 2024-03-02 2605/week @ 2024-03-09 2657/week @ 2024-03-16 1958/week @ 2024-03-23 2148/week @ 2024-03-30 1866/week @ 2024-04-06

9,199 downloads per month
Used in 20 crates (11 directly)

MIT license

27KB
641 lines

random_color

crate badge

Rust crate for generating random attractive colors. Check it out on crates.io.

Inspired by RandomColor by davidmerfield.

Example projects

Amazing rust projects using random_color:

fake-rs — a library for generating fake data in Rust

news-flash — a modern feed reader designed for the GNOME desktop

cargo-trend — cargo subcommand to generate trend graph of dependent crates

light_phylogeny — rust library dedicated to phylogeny

Voronoi — simple program that draws Voronoi cells for a set of points

conways-game-of-life — conways' game of life in rust and with shiny colors

graph-sketchpad — program which allows one to visually create nodes and edges, simply using sdl2

CDCS — helper program for creating Symphony of Empires mods

Using the library

Check the online documentation.

use random_color::color_dictionary::{ColorDictionary, ColorInformation};
use random_color::{Color, Luminosity, RandomColor};

let color = RandomColor::new()
  .hue(Color::Blue) // Optional
  .luminosity(Luminosity::Light) // Optional
  .seed(42) // Optional
  .alpha(1.0) // Optional
  .dictionary(ColorDictionary::new()) //optional
  .to_hsl_string(); // 

// color => "hsl(179, 99%, 10%)"

Hue values

  • Color::Monochrome
  • Color::Red
  • Color::Orange
  • Color::Yellow
  • Color::Green
  • Color::Blue
  • Color::Purple
  • Color::Pink

Luminosity values

  • Luminosity::Random
  • Luminosity::Bright
  • Luminosity::Light
  • Luminosity::Dark

Alpha values

  • You can specify a value between 0 and 1 with .alpha()
  • You can specify a random value with .random_alpha()

Outputs

  // As HSV Array
  let color = RandomColor::new().to_hsv_array(); // color => [179, 20, 100]

  // As RGB String
  let color = RandomColor::new().to_rgb_string(); // color => "rgb(204, 255, 254)"

  // As RGBA String
  let color = RandomColor::new().to_rgba_string(); // color => "rgba(204, 255, 254, 1)"

  // As RGB Array
  let color = RandomColor::new().to_rgb_array(); // color => [204, 255, 254]

  // As HSL String
  let color = RandomColor::new().to_hsl_string(); // color => "hsl(179, 99%, 10%)"

  // As HSLA String
  let color = RandomColor::new().to_hsla_string(); // color => "hsl(179, 99%, 10%, 1)"

  // As HSL Array
  let color = RandomColor::new().to_hsl_array(); // color => [179, 99, 10]
  
  // As Hex String
  let color = RandomColor::new().to_hex(); // color => "#b31464"

Roadmap

  • Iteartor

License

The MIT License (MIT)

Copyright (c) 2017 Lucas Maximiliano Marino

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Dependencies

~310KB