Colorly - Command Line Color Palette Generator

Gem Version Build Status Maintainability


Colorly is a command line utility and a Ruby library for generating color palettes using a simple DSL.

It is a thin wrapper around the chroma gem.

The colorly command line outputs the palette as JSON, YAML or HTML.


Install

$ gem install colorly

Example

Colorly provides you with a simple ruby-based DSL for generating a color palette.

Start by creating this file:

# sample.rb
title "Set 1"
add 'red'.lighten 20
add last.spin 60
add last.spin 60

then run it by calling:

$ colorly sample.rb output.html

output:

For more detailed examples, view the examples folder.

Usage

Colorly scripts are built with a minimalist set of Ruby commands (DSL):

# Start a new color set
title "Any unique name for this set"

# Add colors to this set
add 'yellow'.darken(10).desaturate(10)
add last.spin 20

# Start another set
title "New set"
add '#ff3344'
# ...

The colors provided to the add command can be anything that is supported by Chroma, or an array of the same.

In addition, you can call the below Chroma methods directly on any color. They will be forwarded to Chroma:

'red'.spin        # same as 'red'.paint.spin
'red'.brighten    # same as 'red'.paint.brighten
'red'.darken      # same as 'red'.paint.darken 
'red'.lighten     # same as 'red'.paint.lighten 
'red'.saturate    # same as 'red'.paint.saturate 
'red'.desaturate  # same as 'red'.paint.desaturate 
'red'.greyscale   # same as 'red'.paint.greyscale (also grayscale)
'red'.palette     # same as 'red'.paint.palette

You can use the last added color with the variable last, and generate a random color by calling random:

title "Example"
add 'red'.spin 10
add last.spin 30
add last.spin 30
add random.desaturate 10

Using from Ruby code

If you wish to use Colorly from your own Ruby code, simply load a script to the Script class:

require 'colorly'

# Load from a file
script = Colorly::Script.load 'script_file.rb'

# ... or from a string
script_string = "title 'Hello'; add params[:base_color] ; add last.spin 90"
script = Colorly::Script.new script_string

# Optionally, pass parameters to the script, which you can use in the script
# by accessing the `params` hash.
script.params = { base_color: '#cdc' }
# or
script.params[:base_color] = '#cdc'

# Run it
script.run

# Get its output - each color is a Chroma::Color object
p script.output
p script.output["Hello"].first.class
#=> {"Hello"=>[#ff2b00, #ff5500]}
#=> Chroma::Color

# Get a simplified output where each color is just its hex string
p script.simple_output
#=> {"Hello"=>["#ff2b00", "#ff5500"]}

# Get a simplified output, including color names (slower)
# Get a simplified output, including color names (slower)
pp script.simple_output names: true
#=> {"Hello"=>
#=>   [{:hex=>"#ff2b00", :name=>["Scarlet", "Red"]},
#=>    {:hex=>"#ff5500", :name=>["International Orange", "Orange"]}]}

Contributing / Support

If you experience any issue, have a question or a suggestion, or if you wish to contribute, feel free to open an issue.

Credits