Skip to content

Commit

Permalink
WIP 2
Browse files Browse the repository at this point in the history
  • Loading branch information
PeenScreeker committed Dec 1, 2023
1 parent ba64b0b commit 4829df5
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions scripts/util/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,15 @@ function rgbaStringLerp(colorA: string, colorB: string, alpha: number, useHsv: b

const newRgb: RgbaTuple = HSVToLinearRGB(newHsv) as RgbaTuple;

return tupleToRgbaString(newHsv);
return tupleToRgbaString(newRgb);
}
/** Converts an HSV color to a linear space RGB color */
function HSVToLinearRGB([h, s, v, a]: RgbaTuple): number[] {
// In this color, R = H, G = S, B = V
const Hue = h;
const Saturation = s;
const Value = v;

const HDiv60 = Hue / 60;
const HDiv60_Floor = Math.floor(HDiv60);
const HDiv60_Fraction = HDiv60 - HDiv60_Floor;

const RGBValues: RgbaTuple = [
Value,
Value * (1 - Saturation),
Value * (1 - HDiv60_Fraction * Saturation),
Value * (1 - (1 - HDiv60_Fraction) * Saturation)
];
const hueDir = h / 60;
const hueDir_Floor = Math.floor(hueDir);

Check warning on line 92 in scripts/util/colors.ts

View workflow job for this annotation

GitHub Actions / build

Identifier 'hueDir_Floor' is not in camel case
const hueDir_Fraction = hueDir - hueDir_Floor;

Check warning on line 93 in scripts/util/colors.ts

View workflow job for this annotation

GitHub Actions / build

Identifier 'hueDir_Fraction' is not in camel case

Check warning on line 93 in scripts/util/colors.ts

View workflow job for this annotation

GitHub Actions / build

Identifier 'hueDir_Floor' is not in camel case

const RGBValues: RgbaTuple = [v, v * (1 - s), v * (1 - hueDir_Fraction * s), v * (1 - (1 - hueDir_Fraction) * s)];

Check warning on line 95 in scripts/util/colors.ts

View workflow job for this annotation

GitHub Actions / build

Identifier 'hueDir_Fraction' is not in camel case

Check warning on line 95 in scripts/util/colors.ts

View workflow job for this annotation

GitHub Actions / build

Identifier 'hueDir_Fraction' is not in camel case
const RGBSwizzle = [
[0, 3, 1],
[2, 0, 1],
Expand All @@ -111,7 +101,7 @@ function HSVToLinearRGB([h, s, v, a]: RgbaTuple): number[] {
[3, 1, 0],
[0, 1, 2]
];
const SwizzleIndex = HDiv60_Floor % 6;
const SwizzleIndex = hueDir_Floor % 6;

Check warning on line 104 in scripts/util/colors.ts

View workflow job for this annotation

GitHub Actions / build

Identifier 'hueDir_Floor' is not in camel case

return [
RGBValues[RGBSwizzle[SwizzleIndex][0]] * 255,
Expand Down

0 comments on commit 4829df5

Please sign in to comment.