From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: Color gradients lib
Date: Tue, 08 Feb 2011 16:18:06 +0100
Date: 2011-02-08T16:18:06+01:00 [thread overview]
Message-ID: <op.vqlbggcuule2fv@garhos> (raw)
In-Reply-To: iirlbk$mfc$1@news.eternal-september.org
Le Tue, 08 Feb 2011 15:52:24 +0100, Alex R. Mosteo
<alejandro@mosteo.invalid> a écrit:
> I want a function mapping from some arbitrary values (my data, with its
> minimum and maximum values) into the RGB triplets giving that cold-hot
> representation. Let's say:
>
> type My_Data is float range 0.0 .. 100.0;
>
> type RGB_Component is float range 0.0 .. 1.0;
> type RGB_Color is record R, G, B : RGB_Component; end record;
>
> function Gradient (Value : My_Data) return RGB_Color;
>
> And that's it. Hope this helps, and thanks for the interest.
>
> Alex.
That's easy enough (or else I'm afraid I've missed something), you don't
even need a library for that. You just need to compute a function for each
color channels, y = f(x), where x ranges from 0.0 to 100.0 and where y is
in turn, amount of red, green and blue. Then you use the rounding method
of your choice to map it to an integer value which will be the value for
the associated component of the RGB triplet. The most straightforward
function would be linear: y = y1 + (x * ((y2 - y1) / 100.0)), where y1 is
the value for the color channel for the cold color and y2 the value for
the color channel for the warm color. So if your cold color is (1, 0, 0)
and your warm color is (0, 0, 1), then for x = 0.0, you will get (1,0,0),
for x = 100.0 you will get (0,0,1) and for an intermediate value like x =
50.0 you will get (0.5, 0, 0.5). You may even pre-compute this function at
the application startup, if this does not change during program execution
(you may do so, because in the end you will have integer values anyway).
And voilà, there is no magic :)
Or do I missed something ?
--
Si les chats miaulent et font autant de vocalises bizarres, c’est pas pour
les chiens.
“I am fluent in ASCII” [Warren 2010]
next prev parent reply other threads:[~2011-02-08 15:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-08 10:58 Color gradients lib Alex R. Mosteo
2011-02-08 13:16 ` Yannick Duchêne (Hibou57)
2011-02-08 14:52 ` Alex R. Mosteo
2011-02-08 15:18 ` Yannick Duchêne (Hibou57) [this message]
2011-02-08 15:21 ` Yannick Duchêne (Hibou57)
2011-02-08 16:27 ` Alex R. Mosteo
2011-02-08 19:30 ` Yannick Duchêne (Hibou57)
2011-02-08 18:00 ` Dmitry A. Kazakov
2011-02-08 19:27 ` Yannick Duchêne (Hibou57)
2011-02-08 19:36 ` Yannick Duchêne (Hibou57)
2011-02-08 19:54 ` Dmitry A. Kazakov
2011-02-09 8:53 ` Alex R. Mosteo
2011-02-08 20:26 ` Gautier write-only
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox