Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jpmckinney/color-generator
Ruby gem to randomly generate distinct colors with consistent lightness and saturation
https://github.com/jpmckinney/color-generator
Last synced: 2 months ago
JSON representation
Ruby gem to randomly generate distinct colors with consistent lightness and saturation
- Host: GitHub
- URL: https://github.com/jpmckinney/color-generator
- Owner: jpmckinney
- License: mit
- Created: 2012-09-12T18:43:13.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2021-02-05T18:45:54.000Z (almost 4 years ago)
- Last Synced: 2024-10-13T19:53:41.253Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 21.5 KB
- Stars: 83
- Watchers: 9
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Color Generator
[![Gem Version](https://badge.fury.io/rb/color-generator.svg)](https://badge.fury.io/rb/color-generator)
[![Build Status](https://secure.travis-ci.org/jpmckinney/color-generator.png)](https://travis-ci.org/jpmckinney/color-generator)
[![Coverage Status](https://coveralls.io/repos/jpmckinney/color-generator/badge.png)](https://coveralls.io/r/jpmckinney/color-generator)
[![Code Climate](https://codeclimate.com/github/jpmckinney/color-generator.png)](https://codeclimate.com/github/jpmckinney/color-generator)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
Add `gem 'color-generator'` to your projects `Gemfile` and run `bundle`, or run `gem install color-generator` to install the gem manually.
Then load the library in your code with:
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](http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/) which inspired this gem.
Copyright (c) 2012 James McKinney, released under the MIT license