Skip to content

Examples

ChildrenofkoRn edited this page Oct 3, 2021 · 2 revisions

HEX gradient with a change in lightness, with no change in tone or saturation:

require 'decolmor'
# coefficients, like the method, are for example and are irrelevant:
def get_gradient_on_light(hex, steps = 10, ko = 1.5)
  color = Decolmor.hex_to_hsl(hex)

  (0...steps).flat_map do |n|
    color_step = color.dup
    k = 7 * ( n / ko.to_f)
    color_step[2] += k
    Decolmor.hsl_to_hex(color_step)
  end
end

hex = '#48D1CC'
get_gradient_on_light(hex).reverse

will return:

#F3FCFC
#E0F7F6
#CDF2F1
#BAEEEC
#A7E9E6
#94E4E1
#81DFDC
#6EDBD7
#5BD6D1
#48D1CC

what it looks like:
HSL_gradient

The point of the example is that its easy to change certain color characteristics in HSL/HSV formats.

Clone this wiki locally