27 lines
773 B
TypeScript
27 lines
773 B
TypeScript
export function random_rgba(numShades : number) {
|
|
let o = Math.round, r = Math.random, s = 155, m = 100;
|
|
|
|
let red = o(r()*s + m), green = o(r()*s + m), blue = o(r()*s + m);
|
|
|
|
let result = [];
|
|
|
|
numShades = Math.min(numShades, 3);
|
|
|
|
for(let i = 0; i < numShades; ++i){
|
|
result.push('rgba(' + (red - i*50) + ',' + (green - i*50) + ',' + (blue - i*50) + ',' + 0.8 + ')');
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
export function hexToRGB(hex : string, alpha : number) {
|
|
var r = parseInt(hex.slice(1, 3), 16),
|
|
g = parseInt(hex.slice(3, 5), 16),
|
|
b = parseInt(hex.slice(5, 7), 16);
|
|
|
|
if (alpha) {
|
|
return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
|
|
} else {
|
|
return "rgb(" + r + ", " + g + ", " + b + ")";
|
|
}
|
|
} |