Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
TuyaColorLight.prototype.setColor = function (colorValue) {
debug("Recieved color", colorValue);
if (this._ValIsHex(colorValue)) {
debug("Color is Hex");
var color = convert.hex.hsl(colorValue);
} else {
debug("Color is HSL");
var color = colorValue.split(",");
// convert strings to numbers
color.forEach(function (element, key) {
color[key] = parseInt(element, 10);
});
}
debug("Converted color as HSL", {
0: color[0] + " - " + typeof color[0],
1: color[1] + " - " + typeof color[1],
2: color[2] + " - " + typeof color[2]
})
this.setHSL(color[0], color[1], color[2]);
return this.getDps();
export function getCorrectTextColor(rgb = [0, 0, 0]) {
/*
From this W3C document: http://www.webmasterworld.com/r.cgi?f=88&d=9769&url=http://www.w3.org/TR/AERT#color-contrast
Color brightness is determined by the following formula:
((Red value X 299) + (Green value X 587) + (Blue value X 114)) / 1000
I know this could be more compact, but I think this is easier to read/explain.
*/
if ((typeof rgb === 'string' || rgb instanceof String) && rgb.indexOf('#') > -1) {
rgb = convert.hex.rgb(rgb);
}
console.log({ rgb });
const threshold = 130; /* about half of 256. Lower threshold equals more dark text on dark background */
const [hRed, hGreen, hBlue] = rgb;
const cBrightness = (hRed * 299 + hGreen * 587 + hBlue * 114) / 1000;
if (cBrightness > threshold) {
return '#50616d';
} else {
return '#e9f1f6';
}
}
function getCorrectTextColor(rgb = [0, 0, 0]) {
/*
From this W3C document: http://www.webmasterworld.com/r.cgi?f=88&d=9769&url=http://www.w3.org/TR/AERT#color-contrast
Color brightness is determined by the following formula:
((Red value X 299) + (Green value X 587) + (Blue value X 114)) / 1000
I know this could be more compact, but I think this is easier to read/explain.
*/
if ((typeof rgb === 'string' || rgb instanceof String) && rgb.indexOf('#') > -1) {
console.log('rgb is hex');
rgb = convert.hex.rgb(rgb);
} else if (typeof rgb === 'string') {
console.log('rgb string', rgb);
rgb = getRGB(rgb);
console.log('rgb converted', rgb);
}
console.log({ rgb });
const threshold = 130; /* about half of 256. Lower threshold equals more dark text on dark background */
const [hRed, hGreen, hBlue] = rgb;
const cBrightness = (hRed * 299 + hGreen * 587 + hBlue * 114) / 1000;
if (cBrightness > threshold) {
return '#50616d';
} else {
return '#e9f1f6';
}
createRipple = ({ length }, event, hex, color, node) => {
const body = document.body
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
const piTwo = Math.PI * 2
let rgb = hex ? convert.hex.rgb(hex).join(',') : '0,0,255'
rgb = color ? convert.keyword.rgb(color) : rgb
canvas.style.zIndex = 10000
canvas.style.top = 0
canvas.style.position = 'fixed'
let vw = (canvas.width = window.innerWidth)
let vh = (canvas.height = window.innerHeight)
body.appendChild(canvas)
// Event coords
const x = event.clientX
const y = event.clientY
// Delta - difference between event and farthest corner
.then(state => {
let colorValue;
let colorMode;
const currentState = sanitizeState(state).state;
let briToTurnTo = clamp(normalize(bri || currentState.bri, 255, 100), 1, 100);
if (typeof ct !== 'undefined') {
colorMode = 2;
colorValue = ct;
} else if (typeof hex !== 'undefined') {
colorMode = 1;
colorValue = hexToRgbInt(hex);
// if no bri was specified, calculate from hex value
briToTurnTo = bri ? briToTurnTo : clamp(convert.hex.hsv(hex)[2], 1, 100);
} else if (
typeof hue !== 'undefined' ||
typeof sat !== 'undefined' ||
typeof bri !== 'undefined'
) {
colorMode = 1;
colorValue = hexToRgbInt(
convert.hsv.hex(
normalize(hue || currentState.hue, 65535, 359),
normalize(sat || currentState.sat, 255, 100),
briToTurnTo
)
);
} else if (on) {
return node.serverConfig.yeelight.set_power(on, null, duration);
}
cb(err,null)
} else {
return err,null
}
} else {
var cbin=bytesToHex(currentColorBytes).substring(0,2) + "," + COLORS.hex.rgb(bytesToHex(currentColorBytes).substring(2));
that.saturation = parseInt(cbin.split(",")[0],10)
that.red = parseInt(cbin.split(",")[1],10)
that.green = parseInt(cbin.split(",")[2],10)
that.blue = parseInt(cbin.split(",")[3],10)
if (cb) {
cb(null, that.saturation, that.red, that.green, that.blue, cbin)
//console.log("Playbulb:getColor calling back - cbin=" + cbin + " a=" + that.saturation +
// " r=" + that.red + " g=" + that.green + " b=" +that.blue );
} else {
return null,COLORS.hex.rgb(null, that.saturation, that.red, that.green, that.blue, cbin)
}
}
//console.log("BluetoothManager: Getting Color for " + that.playbulbName + " " +bytesToHex(currentColorBytes) + " conved=" + COLORS.hex.rgb(bytesToHex(currentColorBytes)) + " cbytes=" + currentColorBytes);
});
}.bind(this);
export default (hex: string): ColorType => {
if (!hexRE.test(hex)) {
return {
hex: 'N/A',
cmyk: 'N/A',
rgb: 'N/A'
};
}
return {
hex,
cmyk: convert.hex.cmyk(hex),
rgb: convert.hex.rgb(hex)
};
};
export default (hex: string): ColorType => {
if (!hexRE.test(hex)) {
return {
hex: 'N/A',
cmyk: 'N/A',
rgb: 'N/A'
};
}
return {
hex,
cmyk: convert.hex.cmyk(hex),
rgb: convert.hex.rgb(hex)
};
};
return Bastion.emit('commandUsage', message, this.help);
}
message.channel.send({
embed: {
color: parseInt(args.color, 16),
fields: [
{
name: 'HEX',
value: `#${args.color}`,
inline: true
},
{
name: 'RGB',
value: `${convert.hex.rgb(args.color)}`,
inline: true
},
{
name: 'CMYK',
value: `${convert.hex.cmyk(args.color)}`,
inline: true
},
{
name: 'HSL',
value: `${convert.hex.hsl(args.color)}`,
inline: true
},
{
name: 'HSV',
value: `${convert.hex.hsv(args.color)}`,
inline: true