From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,4370411c07c164af X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news4.google.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Color gradients lib Date: Tue, 08 Feb 2011 16:18:06 +0100 Organization: Ada @ Home Message-ID: References: NNTP-Posting-Host: k+63Xf696+mZElJBiaHO8g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/11.01 (Win32) X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news1.google.com comp.lang.ada:16993 Date: 2011-02-08T16:18:06+01:00 List-Id: Le Tue, 08 Feb 2011 15:52:24 +0100, Alex R. Mosteo = a =C3=A9crit: > I want a function mapping from some arbitrary values (my data, with it= s > 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 ea= ch = color channels, y =3D 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 =3D 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 =3D 0.0, you will get (1,0,= 0), = for x =3D 100.0 you will get (0,0,1) and for an intermediate value like = x =3D = 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 executio= n = (you may do so, because in the end you will have integer values anyway).= = And voil=C3=A0, there is no magic :) Or do I missed something ? -- = Si les chats miaulent et font autant de vocalises bizarres, c=E2=80=99es= t pas pour = les chiens. =E2=80=9CI am fluent in ASCII=E2=80=9D [Warren 2010]