]> git.r.bdr.sh - rbdr/tomato-sauce/blob - lib/renderers/256_colors.js
Use variable for interval
[rbdr/tomato-sauce] / lib / renderers / 256_colors.js
1 'use strict';
2
3 /**
4 * Returns a 256 color, see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
5 * for more info.
6 *
7 * @function 256ColorsRenderer
8 * @implements IRenderer
9 */
10 module.exports = function (red, blue, green) {
11
12 const redValue = Math.round(red * 5 / 255);
13 const blueValue = Math.round(blue * 5 / 255);
14 const greenValue = Math.round(green * 5 / 255);
15
16 const colorNumber = 16 + 36 * redValue + 6 * greenValue + blueValue;
17
18 return `\x1B[48;5;${colorNumber}m`;
19 };