export let colors = [
  0xf2f3f4, 0x222222, 0xf3c300, 0x875692, 0xf38400, 0xa1caf1, 0xbe0032, 0xc2b280, 0x848482,
  0x008856, 0xe68fac, 0x0067a5, 0xf99379, 0x604e97, 0xf6a600, 0xb3446c, 0xdcd300, 0x882d17,
  0x8db600, 0x654522, 0xe25822, 0x2b3d26
];

export function fg(color: number): number {
  // http://www.w3.org/TR/WCAG20/#relativeluminancedef
  let l = (c: number) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
  let r = l((color >> 16) / 255);
  let g = l(((color >> 8) & 0xff) / 255);
  let b = l((color & 0xff) / 255);

  let lum = 0.2126 * r + 0.7152 * g + 0.0722 * b;
  let black_contrast = (lum + 0.05) / 0.05;
  let white_contrast = 1.1 / (lum + 0.05);
  if (white_contrast > black_contrast) {
    return 0xffffff;
  } else {
    return 0;
  }
}

export function hex(color: number): string {
  return '#' + ('000000' + color.toString(16)).slice(-6);
}