Giter Site home page Giter Site logo

Color Map about colorgpt HOT 3 OPEN

sonnylazuardi avatar sonnylazuardi commented on September 26, 2024 5
Color Map

from colorgpt.

Comments (3)

andyg2 avatar andyg2 commented on September 26, 2024 3
  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');

from colorgpt.

andyg2 avatar andyg2 commented on September 26, 2024 3

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.

from colorgpt.

crazy4groovy avatar crazy4groovy commented on September 26, 2024 2

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?? 😂

from colorgpt.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.