Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// use a particular form to set the color either
// color = hex value or named colors
// or set color null and set opt which is an object as {r:x, g:x, b:x}
// values where x is an 8-bit value (0-255);
// opts can contain _sendmsg_ as bool. If set to false message won't be
// sent to firmata - useful for strip level updates to keep message choke down
var pixel = pixels.get(this);
var options = opts || {};
var sendmsg = options.sendmsg || true;
var pixelcolor = null;
if (color) {
// get the color based on a string
pixelcolor = ColorString.getRgb(color) || null;
} else if (opts) {
// set using rgb value
pixelcolor = options.rgb || null;
} else {
return pixel.color;
}
if (pixelcolor != null) {
// fill out the values for the pixel and then send the message to update
// it on the strip
with (pixel.color) {
r = pixelcolor[0];
g = pixelcolor[1];
b = pixelcolor[2];
hexcode = ColorString.hexString(pixelcolor);
Strip.prototype.color = function(color, opts) {
// sets the color of the entire strip
// use a particular form to set the color either
// color = hex value or named colors
// or set color null and set opt which is an object as {rgb: [rx, gx, bx]}
// values where x is an 8-bit value (0-255);
var strip = strips.get(this);
var stripcolor = null;
if (color) {
// use text to determine the color
stripcolor = ColorString.getRgb(color) || null;
} else if (opts) {
// use rgb array to determine color
stripcolor = opts.rgb || null;
}
if (stripcolor != null) {
// fill out the values for the pixels and then update the strip
// TODO get this to update all of the pixels
/** for (pixel in strip.pixels) {
pixel.
}**/
color = ColorString.colorValue(stripcolor);
var msg = "{a:" + color + "}";
['color', 'background'].forEach((prop) => {
let
value = style[prop],
num = 30 + (prop === 'background' ? 10 : 0),
index, c;
if (index = BASIC_COLOR.indexOf(value), index !== -1) {
props.push(num + index);
} else if (c = color.getRgb(value)) {
// if `rule.consoleRgb` is true, it uses RGB color.
props.push((num + 8) + ';' + (this.rule.consoleRgb ? '2;' + c.join(';') : '5;' + color256(c)));
} else if (typeof value !== 'undefined') {
props.push(value);
}
});
i += 1;
case 'magenta':
i += 1;
case 'blue':
i += 1;
case 'yellow':
i += 1;
case 'green':
i += 1;
case 'red':
i += 1;
case 'black':
return ''+i;
}
if (c = color.getRgb(value)) {
return config.consoleRgb ? (i+8) + ';2;' + c.join(';') : (i+8) + ';5;' + color256(c);
}
return value;
default:
return '';
}
};
function rgb(str) {
return colorString.getRgb(str).map(function(c) {
return c/255
})
}