Improve and fix issues with color generation

This commit is contained in:
2024-08-10 19:36:26 +02:00
parent 84002d1856
commit 376201373e
3 changed files with 12 additions and 5 deletions

View File

@@ -1,10 +1,11 @@
<script lang="ts">
import { GenerateColor } from "$lib/utils";
import { GenerateColor, RemoveExistingColors } from "$lib/utils";
import { main } from "$wails/models";
import EmptyFoodComp from "./EmptyFoodComp.svelte";
import FoodComp from "./FoodComp.svelte";
export let items: main.Food[] = [];
RemoveExistingColors();
let minCal = 1e5;
let maxCal = 0;

View File

@@ -1,10 +1,11 @@
<script lang="ts">
import { GenerateColor } from "$lib/utils";
import { GenerateColor, RemoveExistingColors } from "$lib/utils";
import EmptyWeightComp from "$components/Weight/EmptyWeightComp.svelte";
import WeightComp from "$components/Weight/WeightComp.svelte";
import { main } from "$wails/models";
export let items: main.Weight[] = [];
RemoveExistingColors();
const dateColors: Map<string, string> = new Map<string, string>();

View File

@@ -68,8 +68,11 @@ function GenerateRandomHSL(): Color {
const existingColors: Color[] = [];
function RemoveExistingColors() {
existingColors.length = 0;
}
function GenerateColor(): string {
const minDistance = 15;
const minDistance = 5;
let newColor: Color;
let isDistinct = false;
@@ -89,7 +92,9 @@ function GenerateColor(): string {
break;
}
}
existingColors.push(newColor);
if (isDistinct) {
existingColors.push(newColor);
}
}
// We can not reach this point without having a color generated
@@ -104,5 +109,5 @@ function LerpColor(color1: Color, color2: Color, t: number): Color {
return { h, s, l };
}
export { GenerateColor, LerpColor };
export { GenerateColor, LerpColor, RemoveExistingColors };
export type { Color };