Open andyg2 opened 1 year ago
function get_closest(hex) {
let color = hex.toUpperCase();
let minDistance = Number.MAX_SAFE_INTEGER;
let closestColorName = '';
for (let c in colors) {
let distance = getDistance(color, c);
if (distance < minDistance) {
minDistance = distance;
closestColorName = colors[c];
}
}
return closestColorName;
}
function getDistance(c1, c2) {
let r1 = parseInt(c1.substr(0, 2), 16);
let g1 = parseInt(c1.substr(2, 2), 16);
let b1 = parseInt(c1.substr(4, 2), 16);
let r2 = parseInt(c2.substr(0, 2), 16);
let g2 = parseInt(c2.substr(2, 2), 16);
let b2 = parseInt(c2.substr(4, 2), 16);
let dr = r1 - r2;
let dg = g1 - g2;
let db = b1 - b2;
return Math.sqrt(dr * dr + dg * dg + db * db);
}
let closest = get_closest('ADF0FE');
This review doesn't even mention color names, lol.
https://youtu.be/k0OhVtxJHMA?t=365
When I saw that I was like, why do I need to to connect chatGPT for a color grabber?? 😂
Because there's 16 million possible colors to name. Even if you count the fact that some of them have the same color, you still have to build through a database that big and search through it.
ChatGPT doesn't know 16M color names, it knows 480, well that's all I could get out of it by asking e.g. what color names are between eggshell and pearl. The code above gets the closest color name to any of the 16M hex codes. There's 550 colors in the list.
Tearing through your API allowance 10 times a second, is horrific.
Wouldn't this be a lot more efficient, it's more colors that ChatGPT knows.