Exemplo n.º 1
0
		const source = (source => {
			switch (source.space) {
				case 'HEX':
				case '#HEX':
					const [input, r, g, b] = source.input
					return {
						name: `${r}${r}${g}${g}${b}${b}`,
						rgb: converter.hex.rgb(`${r}${r}${g}${g}${b}${b}`),
						input
					}
				case 'HEXHEX':
				case '#HEXHEX':
					return {
						name: source.input,
						rgb: converter.hex.rgb(this.name)
					}
				case 'RGB':
					return {
						name: converter.rgb.hex(source.input),
						rgb: converter.hex.rgb(this.name)
					}
				case 'HSL':
					return {
						name: converter.hsl.hex(source.input),
						rgb: converter.hsl.rgb(source.input)
					}
				case 'HSV':
					return {
						name: converter.hsv.hex(source.input),
						rgb: converter.hsv.rgb(source.input)
					}
				case 'HWB':
					return {
						name: converter.hwb.hex(source.input),
						rgb: converter.hwb.rgb(source.input)
					}
				case 'SGR':
					return {
						name: source.input,
						rgb: source.input
					}
				case 'named':
					return {
						name: converter.keyword.hex(source.input),
						rgb: converter.keyword.rgb(source.input)
					}
				default:
					throw new Error(`Unrecognised color space: ${source.space}`)
			}
		})(this.source)
Exemplo n.º 2
0
      value: function(r, g, b) {
        var rgb = [r, g, b];
        if (arguments.length === 1) {
          if (Array.isArray(r)) {
            rgb = r;
          }
          if (typeof r === "string") {
            rgb = converter.keyword.rgb(r);
            if (rgb === undefined) {
              if (r.startsWith("#")) {
                r = r.slice(1);
              }
              rgb = converter.hex.rgb(r);
            }
          }
        }

        if (rgb === undefined) {
          throw new Error("Invalid RGB value");
        }

        [0x04, 0x03, 0x02].forEach(function(cmd, i) {
          this.io.i2cWrite(this.address.rgb, [cmd, rgb[i]]);
        }, this);

        return this;
      }
Exemplo n.º 3
0
Arquivo: colors.js Projeto: jxnblk/c0
export const darken = c => d => {
  const hex = toHex(c) // c.split('#')[1]
  const rgb = toRgb(''+ hex)
  const althsl = toHsl(rgb)

  const hsl = convert.hex.hsl(hex)
  hsl[2] = hsl[2] * d

  const val = convert.hsl.hex(...hsl)
  console.log('convert', hex, hsl, val, '(rgb)', rgb)
  return val
}