Skip to content

Instantly share code, notes, and snippets.

View thgh's full-sized avatar
💭
#PWA

Thomas Ghysels thgh

💭
#PWA
View GitHub Profile
@thgh
thgh / color.lighten.ts
Last active July 1, 2020 07:59 — forked from renancouto/color.lighten.js
Method to lighten / darken hex colors using Javascript.
export function lighten(color = '#004488', opacity = 1) {
// Convert to color channels
const num = parseInt(color.slice(1), 16)
let R = num >> 16,
G = (num >> 8) & 0x00ff,
B = num & 0x0000ff
// Interpolate channel
opacity = Math.min(Math.max(opacity, 0), 1)
R = Math.round(R + (1 - opacity) * (255 - R))