Skip to content

Instantly share code, notes, and snippets.

@newshorts
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newshorts/10482560 to your computer and use it in GitHub Desktop.
Save newshorts/10482560 to your computer and use it in GitHub Desktop.
Translate any rgb value to 256 8-bit colors and back. Use the 'color' value as a key to the array in the json file.
["0,0,0",
"35,0,1",
"71,1,2",
"107,2,6",
"142,4,10",
"178,6,16",
"214,9,21",
"249,13,27",
"1,35,2",
"36,36,2",
"71,36,4",
"107,36,7",
"142,37,12",
"178,38,17",
"214,39,22",
"249,40,28",
"5,71,6",
"37,71,6",
"72,71,8",
"107,72,11",
"143,72,15",
"178,72,20",
"214,73,24",
"249,73,30",
"11,107,13",
"39,107,14",
"73,107,15",
"108,107,18",
"143,107,21",
"179,108,24",
"214,108,28",
"250,108,33",
"18,143,22",
"42,143,22",
"75,143,23",
"109,143,24",
"144,143,27",
"179,143,30",
"214,143,33",
"250,143,37",
"26,178,30",
"46,178,30",
"77,178,31",
"110,178,32",
"145,178,34",
"180,179,36",
"215,179,39",
"250,179,42",
"undefined",
"51,214,38",
"79,214,39",
"112,214,40",
"146,214,41",
"181,214,43",
"216,214,46",
"251,214,48",
"undefined",
"56,250,46",
"82,250,46",
"114,250,47",
"147,250,49",
"182,250,50",
"217,250,52",
"252,250,55",
"1,5,83",
"36,6,83",
"71,6,84",
"107,7,84",
"142,9,85",
"178,11,86",
"214,14,87",
"249,17,88",
"2,37,84",
"36,37,84",
"71,38,84",
"107,38,84",
"142,39,85",
"178,39,86",
"214,40,87",
"249,42,88",
"6,72,84",
"37,72,84",
"72,72,85",
"107,72,85",
"143,73,86",
"178,73,87",
"214,74,88",
"249,74,89",
"12,107,85",
"40,107,85",
"73,108,86",
"108,108,86",
"143,108,87",
"179,108,88",
"214,108,89",
"250,109,90",
"19,143,87",
"43,143,87",
"75,143,87",
"109,143,88",
"144,143,88",
"179,143,89",
"214,144,90",
"250,144,92",
"26,179,89",
"46,179,89",
"77,179,89",
"110,179,90",
"145,179,90",
"180,179,91",
"215,179,92",
"250,179,94",
"undefined",
"51,214,92",
"79,214,92",
"112,214,92",
"146,214,93",
"181,214,94",
"216,215,95",
"251,215,96",
"undefined",
"56,250,95",
"82,250,95",
"114,250,96",
"148,250,96",
"182,250,97",
"217,250,98",
"252,250,99",
"4,20,167",
"37,20,167",
"72,21,167",
"107,21,167",
"143,22,168",
"178,24,168",
"214,25,168",
"249,27,169",
"6,43,167",
"37,43,167",
"72,43,167",
"107,44,167",
"143,44,168",
"178,45,168",
"214,46,169",
"249,47,169",
"9,75,167",
"39,75,167",
"73,75,167",
"108,75,168",
"143,76,168",
"178,76,168",
"214,77,169",
"249,77,169",
"15,109,168",
"41,109,168",
"74,109,168",
"108,109,168",
"143,110,168",
"179,110,169",
"214,110,169",
"250,111,170",
"21,144,169",
"44,144,169",
"75,144,169",
"109,144,169",
"144,145,169",
"179,145,169",
"215,145,170",
"250,145,171",
"28,180,169",
"47,180,169",
"77,180,170",
"111,180,170",
"145,180,170",
"180,180,170",
"215,180,171",
"251,180,172",
"undefined",
"52,215,171",
"80,215,171",
"112,215,171",
"146,215,171",
"181,215,172",
"216,215,172",
"251,215,173",
"undefined",
"57,250,172",
"83,250,172",
"114,250,173",
"148,251,173",
"182,251,173",
"217,251,174",
"252,251,174",
"undefined",
"undefined",
"undefined",
"undefined",
"undefined",
"undefined",
"undefined",
"undefined",
"12,52,251",
"40,52,251",
"73,53,251",
"108,53,251",
"143,53,251",
"179,54,251",
"214,54,252",
"250,55,252",
"15,80,251",
"41,80,251",
"74,80,251",
"108,81,251",
"143,81,251",
"179,81,251",
"214,82,252",
"250,82,252",
"19,113,251",
"43,113,251",
"75,113,251",
"109,113,251",
"144,113,251",
"179,113,252",
"214,114,252",
"250,114,252",
"25,147,252",
"45,147,252",
"76,147,252",
"110,147,252",
"145,147,252",
"180,147,252",
"215,147,252",
"250,148,253",
"31,181,252",
"49,181,252",
"78,181,252",
"111,181,252",
"146,182,252",
"180,182,253",
"215,182,253",
"251,182,253",
"undefined",
"53,216,253",
"81,216,253",
"113,216,253",
"147,217,253",
"181,217,253",
"216,217,254",
"251,217,254",
"undefined",
"58,252,254",
"84,252,254",
"115,252,254",
"148,252,254",
"182,252,254",
"217,252,255",
"255,255,255"]
int color = ((b&255 & 0xC0)+((g&255 & 0xE0) >> 2)+((r & 0xE0) >> 5))&0xFF;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment