INNER CODE UNIT · JavaScript
nearest_color_in_palette
increpare/flickgame · flickgame_base.js:74
function nearest_color_in_palette(palette, target_color) {
return palette[nearest_color_index_in_palette(palette, target_color)];
}
// Returns "#ffffff" or "#000000" for best contrast against the given hex color
function contrastTextColor(hex) {
var dw = color_distance(hex, "#ffffff");
var db = color_distance(hex, "#000000");
return dw > db ? "#ffffff" : "#000000";
}
// RLE decode function.
// Run counts come straight from an untrusted game file, so targetLength (when given)
// bounds the output and pads it out: an oversized count used to build an enormous
// string and lock the tab up for minutes.
function RLE_decode(encoded, targetLength) {
if (!encoded || typeof encoded.length !== 'number') encoded = [];
var limit = (typeof targetLength === 'number' && targetLength >= 0) ? targetLength : Infinity;