Giter Club home page Giter Club logo

color-generator's Introduction

Color Generator

Gem Version Build 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.