Skip to content

Commit

Permalink
WIP cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
PeenScreeker committed Dec 1, 2023
1 parent 9ca67cf commit d41df54
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions scripts/util/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ type colorTuple = RgbTuple | RgbaTuple;

// __brand is a compile time-only type trick to make these two incompatible,
// even though they're really just `string`s.
type RgbString = string /* & { __brand: 'rgb' }*/;
type RgbaString = string /* & { __brand: 'rgba' }*/;
type RgbString = string;
type RgbaString = string;

/**
* Returns a string formatted: `rgb(R, G, B)` from RGB number tuple, where
Expand Down Expand Up @@ -62,11 +62,7 @@ function rgbaStringToTuple(str: RgbaString): RgbaTuple {
*/
function rgbaTupleLerp(colorA: RgbaTuple, colorB: RgbaTuple, alpha: number): RgbaTuple {
const interp = Math.max(Math.min(alpha, 1), 0);
const colorResult: RgbaTuple = [0, 0, 0, 0];
for (let i = 0; i < 4; ++i) {
colorResult[i] = Math.round(colorA[i] + interp * (colorB[i] - colorA[i]));
}
return colorResult as RgbaTuple;
return (colorA as number[]).map((Ai, i) => Math.round(Ai + interp * (colorB[i] - Ai))) as RgbaTuple;
}

/**
Expand Down

0 comments on commit d41df54

Please sign in to comment.