Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Ruby gem to randomly generate distinct colors with consistent lightness and saturation
branch: master
Failed to load latest commit information.
lib use https links
spec ColorGenerator now uses the hue from options, if provided
.gitignore first commit
.travis.yml drop official 1.8.7 support
.yardopts add .yardopts
Gemfile use https links
LICENSE reassign copyright
README.md use https links
Rakefile first commit
USAGE first commit
color-generator.gemspec use https links

README.md

Color Generator

Gem Version Build Status Dependency Status Coverage Status Code Climate

This gem randomly generates very distinct colors with consistent lightness and saturation.

If you are using these colors as background colors, consistent lightness lets you use the same foreground color for each. Consistent saturation lets you avoid mixing pastels with vibrant colors, etc.

Usage

require 'color-generator'

Generate colors using the HSL color representation:

generator = ColorGenerator.new saturation: 0.3, lightness: 0.75
color1 = generator.create_hex
# => "cfd2ac"
color2 = generator.create_hex
# => "cbacd2"

Generate colors using the HSV color representation:

generator = ColorGenerator.new saturation: 0.3, value: 1.0
color1 = generator.create_hex
# => "f7b3ff"
color2 = generator.create_hex
# => "b3ffe0"

If you want to make color generation repeatable, set a seed for the pseudorandom number generator:

generator = ColorGenerator.new saturation: 0.3, value: 1.0, seed: 12345

If you prefer a decimal RGB value, call create_rgb instead of create_hex.

Acknowledgements

Thanks to Martin Ankerl for his blog post which inspired this gem.

Copyright (c) 2012 James McKinney, released under the MIT license

Something went wrong with that request. Please try again.