How to use the chroma-js.rgb function in chroma-js

To help you get started, we’ve selected a few chroma-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github internalfx / distinct-colors / src / index.js View on Github external
var checkColor = function (lab, options) {
  const color = chroma.lab(lab)
  const hcl = color.hcl()
  const rgb = color.rgb()
  const compLab = chroma.rgb(rgb).lab()
  const labTolerance = 2

  return (
    hcl[0] >= options.hueMin &&
    hcl[0] <= options.hueMax &&
    hcl[1] >= options.chromaMin &&
    hcl[1] <= options.chromaMax &&
    hcl[2] >= options.lightMin &&
    hcl[2] <= options.lightMax &&
    compLab[0] >= (lab[0] - labTolerance) &&
    compLab[0] <= (lab[0] + labTolerance) &&
    compLab[1] >= (lab[1] - labTolerance) &&
    compLab[1] <= (lab[1] + labTolerance) &&
    compLab[2] >= (lab[2] - labTolerance) &&
    compLab[2] <= (lab[2] + labTolerance)
  )
github jxnblk / figma-theme / index.js View on Github external
const colorArray = colorStyles.map(style => {
    const child = children
      .find(child => get(child, 'styles.fill') === style.id)
    if (!child) return

    const [ fill = {} ] = child.fills || []
    const { r, g, b, a } = fill.color
    const rgb = [ r, g, b ].map(n => n * 255)
    const color = chroma.rgb(rgb)
    return {
      id: style.id,
      name: style.name,
      value: color.hex()
    }
  })
  .filter(Boolean)
github SaxonF / figma-portfolio / api / portfolio / figmaPortfolio.js View on Github external
const Project = (node) => {
  const {
    r,
    g,
    b,
    a
  } = node.backgroundColor;
  const rgb = [r, g, b].map(n => n * 255);
  const colorHex = chroma.rgb(rgb).hex();

  return {
    name: node.name,
    background: colorHex,
    id: node.id
  }
}