UNPKG

@chayns/colors

Version:

JavaScript utility functions for the calculation of colors for chayns

32 lines (31 loc) 952 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRandomHexColor = getRandomHexColor; exports.getRandomRgb255Color = getRandomRgb255Color; var _converter = require("../converter"); function getRandomRgb255Color() { var transparency = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; var rgb = { r: null, g: null, b: null }; if (transparency) { rgb.a = null; } for (var i = 0; i < Object.keys(rgb).length; i += 1) { var component = Object.keys(rgb)[i]; rgb[component] = Math.random(); if (component !== 'a') { rgb[component] = Math.round((rgb[component] || 0) * 255); } } return rgb; } function getRandomHexColor() { var transparency = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; return (0, _converter.rgb255ToHex)(getRandomRgb255Color(transparency)); } //# sourceMappingURL=randomColor.js.map