Okay, maybe it is me.
(255*(x-6))/451
On Tue, Dec 20, 2011 at 9:03 AM, James Stuart <[log in to unmask]> wrote:
> 255 * (point - data.min) / (data.max - data.min)
>
> On Tue, Dec 20, 2011 at 11:57 AM, Nate Hill <[log in to unmask]> wrote:
>> Here's a brain teaser for the mathematically inclined:
>>
>> I've got a set of values that I want to scale to the 0-255 range so that I
>> can adjust colors in my CSS.
>> Say I have the following data: (6, 457, 97, 200, 122).
>> I'd like to scale those numbers so that the highest one, 475 = 255.
>> and the lowest one, 6 = 0.
>> All of the other numbers, 97, 200, and 122 should be scaled proportionally
>> to fit within the range.
>>
>> This way, when I loop through and hit my CSS {background-color:rgb(255,
>> **data**, 255);} each piece of data will generate a different color and
>> I'll have the maximum spread in proportionally correct colors from 0-255.
>>
>> There's probably some math operation to do this, but I know I paid far too
>> little attention in math class as a kid. "When will I ever need to use
>> this stuff in *real life*", I asked the teacher with a sneer.
>>
>> If anyone could point me in the right direction I'd appreciate it.
>>
>> --
>> Nate Hill
>> [log in to unmask]
>> http://www.natehill.net
--
Cary Gordon
The Cherry Hill Company
http://chillco.com
|