INNER CODE UNIT · JavaScript

dL

increpare/flickgame · flickgame_base.js:60

    var dL = lab1.L - lab2.L, dA = lab1.a - lab2.a, dB = lab1.b - lab2.b;
    return Math.sqrt(dL * dL + dA * dA + dB * dB);
}

function nearest_color_index_in_palette(palette, target_color) {
    var nearest_idx = 0;
    var nearest_dist = color_distance(target_color, palette[0]);
    for (var i = 1; i < palette.length; i++) {
        var dist = color_distance(target_color, palette[i]);
        if (dist < nearest_dist) { nearest_dist = dist; nearest_idx = i; }
    }
    return nearest_idx;
}

function nearest_color_in_palette(palette, target_color) {
    return palette[nearest_color_index_in_palette(palette, target_color)];
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…