Elements 0.6.8 (23389)

We generate 13 colours and drop the first and last, otherwise we get a black and white on every gradient. I wouldn’t get too hung up on it; it’s just there as a means to generate gradients quickly. We’ll probably refine it further in the future.

Here’s the code we currently use… and yes, we’re open to improvements :blush:

import chroma from "chroma-js"

rw.color = function(colorJS) {

    const brightness = colorJS.brightness
    const actualColor = chroma(colorJS.color)

    const lightColor = chroma(colorJS.color)
        .luminance(1.0)

    const darkColor = chroma(colorJS.color)
        .luminance(0.0)

    var colors = chroma
        .scale([lightColor, actualColor, darkColor])
        .domain([0, brightness / 10, 1.0])
        .mode('lab')
        .colors(13)

    // Add 1 because we generate 13 colors and strip the first/last
    colors[brightness + 1] = colorJS.color

    // Return the middle 11 colors
    colorJS.colors = colors.splice(1,11)
}