How to use the chroma-js.lab 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 Evercoder / culori / test / benchmarks / conversions / lab.js View on Github external
let chroma = require('chroma-js');
let { map, rgb, lab: lab2 } = require('../../../');

const getLabValues = () => {
	return {
		l: Math.floor(Math.random() * 100),
		a: Math.floor(Math.random() * 200 - 100),
		b: Math.floor(Math.random() * 200 - 100)
	}
}

for (var i = 0; i < 100; i++) {
	let color = getLabValues();
	console.log('\n-----\n');
	console.log(color);
	console.log('chroma', chroma.lab(color.l, color.a, color.b));
	console.log('d3-color', lab(color.l, color.a, color.b).rgb());
	console.log('culori', map(rgb(lab2(color)), (k,v) => 'rgb'.indexOf(k) > -1 ? v * 255 : v ));

}
// 
// console.log('d3-color\n', lab("#abcdef"), lab("#abcdef").rgb());
// console.log('culori\n', lab2("#abcdef"), map(rgb(lab2("#abcdef")), (k,v) => 'rgb'.indexOf(k) > -1 ? v * 255 : v ));
github internalfx / distinct-colors / src / index.js View on Github external
  return colors.map((lab) => { return chroma.lab(lab) })
}
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) &&