16 lines
538 B
TypeScript
16 lines
538 B
TypeScript
const FIRST_HUE = 18;
|
|
const GOLDEN_ANGLE = 137.508;
|
|
const HUE_CYCLE = 360;
|
|
|
|
export function generateUniqueSoundColor(existingColors: readonly string[]): string {
|
|
const existing = new Set(existingColors);
|
|
|
|
for (let index = existingColors.length; index < existingColors.length + HUE_CYCLE; index += 1) {
|
|
const hue = ((FIRST_HUE + index * GOLDEN_ANGLE) % HUE_CYCLE).toFixed(2);
|
|
const color = `hsl(${hue} 76% 65%)`;
|
|
if (!existing.has(color)) return color;
|
|
}
|
|
|
|
throw new Error('Unable to generate a unique sound color.');
|
|
}
|