Files
2024-06-25 20:10:17 +02:00

43 lines
1.1 KiB
TypeScript

import { DrinkType } from "@prisma/client";
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 + ")";
}
}
export function drinkTypeToColor(type: DrinkType){
switch(type){
default:
case "Beer":
return 'rgba(255, 164, 18, 1)';
case "Cocktail":
return 'rgba(83, 185, 219, 1)';
case "Soda":
return 'rgba(188, 71, 214, 1)';
case "Wine":
return 'rgba(178, 21, 58, 1)'
}
}