10

I just answered a question in which the OP basically wants a mathematical model for doing interpolation between color points in a way which would look natural to the human eye (and which presumably is not what linear interpolation would produce).

My answer was to pre-pick N colors and simply project from the initial input range to these color bands.

Which led me to wonder... how is it done here on SO?

4
  • Can you point to a post that has comments with upvote counts in different colors?
    – Gabe
    Commented Apr 4, 2011 at 0:15
  • @Gabe: The highest voted question (stackoverflow.com/questions/194812/…) has some variety.
    – Jon
    Commented Apr 4, 2011 at 0:16
  • I see. The styles are "cool", "warm", "hot", and "supernova".
    – Gabe
    Commented Apr 4, 2011 at 0:23
  • 1
    Translate RGB to the HSL color space. Different S. It's a bit off, they probably picked them from a table. Commented Apr 4, 2011 at 0:33

1 Answer 1

12

css

.supernova {
color: #FE7A15 !important;
}

.hot {
color: #CF7721 !important;
}

.warm {
color: #9B764F !important;
}

.cool {
color: #999 !important;
}

js

// e.g. options = { min: 15, max: 300, setIsValid: function }

var max = options.max;

var css = cur > max * 0.8 ? "supernova" : cur > max * 0.6 ? "hot" : cur > max * 0.4 ? "warm" : "cool";
2
  • 3
    Thanks for taking the time to dig.
    – Jon
    Commented Apr 4, 2011 at 16:49
  • I love the shorthand if statements in the last line. Commented Sep 26, 2012 at 16:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .