Method: Chroma::Harmonies#monochromatic

Defined in:
lib/chroma/harmonies.rb

#monochromatic(options = {}) ⇒ Array<Color>, Array<String>

Generate a monochromatic palette.

Examples:

'red'.paint.palette.monochromatic           #=> [red, #2a0000, #550000, maroon, #aa0000, #d40000]
'red'.paint.palette.monochromatic(as: :hex) #=> ['#ff0000', '#2a0000', '#550000', '#800000', '#aa0000', '#d40000']
'red'.paint.palette.monochromatic(size: 3)  #=> [red, #550000, #aa0000]

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :size (Symbol) — default: 6

    number of results to return

  • :as (Symbol) — default: nil

    optional format to output colors as strings

Returns:

  • (Array<Color>, Array<String>)

    depending on presence of options[:as]



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/chroma/harmonies.rb', line 106

def monochromatic(options = {})
  size = options[:size] || 6

  h, s, v = @color.hsv
  modification = 1.0 / size

  palette = size.times.map do
    Color.new(ColorModes::Hsv.new(h, s, v), @color.format).tap do
      v = (v + modification) % 1
    end
  end

  with_reformat(palette, options[:as])
end