This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable @typescript-eslint/naming-convention */ | |
/* eslint-disable no-loss-of-precision */ | |
// Source: https://drafts.csswg.org/css-color-4/conversions.js | |
// Sample code for color conversions | |
// Conversion can also be done using ICC profiles and a Color Management System | |
// For clarity, a library is used for matrix multiplication (multiply-matrices.js) | |
export type Color = [number, number, number] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function rgbToHsl(rgb) { | |
const r = rgb.r / 255 | |
const g = rgb.g / 255 | |
const b = rgb.b / 255 | |
const max = Math.max(r, g, b), min = Math.min(r, g, b) | |
let h, s, l = (max + min) / 2 | |
if (max == min) { | |
h = s = 0 // achromatic |