Skip to content

Instantly share code, notes, and snippets.

View Myndex's full-sized avatar
💭
👁💡👀

Myndex Myndex

💭
👁💡👀
View GitHub Profile
@rich-iannone
rich-iannone / gt-color-contrast-computation-comparison.R
Last active October 20, 2023 15:31
This gist generates a gt table that compares text color choices from the WCAG and APCA contrast methods. Implemented in the `data_color()` function of the gt package, where the background is set first (based on cell data) and the color of the overlaid text is determined from the color contrast algorithm.
library(gt)
library(tidyverse)
color_sequence <- seq_along(grDevices::colors())
dplyr::tibble(
x11c = grDevices::colors(),
wcag = color_sequence,
apca = color_sequence
) %>%
@mnpenner
mnpenner / color.ts
Last active April 22, 2024 02:41
RGB color hex to lightness
// based on https://stackoverflow.com/a/56678483/65387
type RGB = [r: number, g: number, b: number]
const UNK = 255 / 2
/**
* @param hex RGB hex string like "#CCCFDB"
* @returns RGB tuple in [0-255]
*/
@hail2u
hail2u / apca.js
Last active September 11, 2023 05:18
Get contrast of colors using APCA (Advanced Perceptual Contrast Algorithm)
// https://github.com/Myndex/SAPC-APCA#the-plain-english-steps-are
// Example:
// const contrast = getAPCAContrast("rgb(255, 255, 255)", "rgb(136, 136, 136)");
// This returns `66.89346308821438` (66.893%)
// SAPC-APCA README says:
// > #888 vs #fff • 66.89346308821438
// 80% means 7:1 in WCAG 2.0
// 60% means 4.5:1 in WCAG 2.0
@mbostock
mbostock / .block
Last active January 16, 2020 05:25
Lab Color Picker
license: gpl-3.0