Skip to main content

Gradient Scales

Generate an array of colors from color1 to color2. Methods available are rgb, hsv, hsl, hsi, hsp, and cmyk.

.scheme('gradient',{
color2: colorType, // REQUIRED, second color, of any type, to blend with
colors: number, // REQUIRED, number of colors to be returned, must be > 2
method: string, // optional, defaults to 'rgb'
round: boolean // optional, defaults to true
})

Gradient Methodsโ€‹

methoddescription
rgbBlends each RGBA value
hsvBlends each HSVA value
hslBlends each HSLA value
hspBlends each HSPA value
cmykBlends each CMYK value
labBlends each L*a*b* value
luvBlends each L*u*v* value
hueBlends hue only
valueBlends value (HSV) only
lightnessBlends lightness (HSL) only
intensityBlends intensity (HSI) only
perceivedbrightnessBlends perceived brightness (HSP) only
screenRGB values are inverted, multiplied, then inverted again
multiplyRGB values are multiplied
overlayScreen or multiply depending on whether second color values are lighter or darker
softlightSimilar to overlay; uses W3C formula
divideFirst color values divided by second
subtractionSecond color values subtracted from first color
differenceDifference between each value pair
colorburnDivites inverted bottom layer by top layer
colordodgeDivides bottom layer by inverted top layer
vividlightColor dodge or burn, depending on which value is lighter
linearburnSums each value pair and subtracts 1
lineardodgeSums each value pair
linearlightLinear dodge or burn, depending on which value is lighter

JavaScriptโ€‹

const Color = require('chromaticity-color-utilities')

const gradient1 = Color.from('rgb', [255, 0, 255]).scheme('gradient', {
with: Color.from('hex', 0x00ff00),
colors: 5,
})
// [
// rgb { r: 255, g: 0, b: 255, a: 255, bitDepth: 8, max: 255 },
// rgb { r: 191, g: 64, b: 191, a: 255, bitDepth: 8, max: 255 },
// rgb { r: 128, g: 128, b: 128, a: 255, bitDepth: 8, max: 255 },
// rgb { r: 64, g: 191, b: 64, a: 255, bitDepth: 8, max: 255 },
// rgb { r: 0, g: 255, b: 0, a: 255, bitDepth: 8, max: 255 }
// ]

const gradient1 = Color.from('rgb', [255, 0, 255]).scheme('gradient', {
with: Color.from('hex', '00ff00'),
colors: 5,
method: 'hsv',
})
// [
// rgb { r: 255, g: 0, b: 255, a: 255, bitDepth: 8, max: 255 },
// rgb { r: 64, g: 0, b: 255, a: 255, bitDepth: 8, max: 255 },
// rgb { r: 0, g: 128, b: 255, a: 255, bitDepth: 8, max: 255 },
// rgb { r: 0, g: 255, b: 191, a: 255, bitDepth: 8, max: 255 },
// rgb { r: 0, g: 255, b: 0, a: 255, bitDepth: 8, max: 255 }
// ]

TypeScriptโ€‹

import Color from 'chromaticity-color-utilities'

const gradient1: Color.rgb[] = Color.from('rgb', [255, 0, 255]).scheme(
'gradient',
{
with: Color.from('hex', 0x00ff00),
colors: 5,
}
)