[reportlab-users] HexColor()

Magnus Lycka reportlab-users@reportlab.com
Sat, 15 Feb 2003 01:55:30 +0100


At Fri, 14 Feb 2003 14:17:35 -0200, Lalo Martins wrote:
>On Fri, Feb 14, 2003 at 09:53:16AM +0200, Marius Gedminas wrote:
> > On Thu, Feb 13, 2003 at 07:02:24PM -0200, Lalo Martins wrote:
> > > One additional feature my customer wanted is that it allows any 
> "width" for
> > > each color, so "f90" and "f09000" and "f00900000" are equivalent.
> >
> > Shouldn't that be F90 == ff9900 == ffff99990000?  Both W3C and X11 agree
> > on this convention.
>
>I thought so initially, but these aren't numerically equivalent:
>
> >>> from __future__ import division
> >>> 0x90 / 0x100
>0.5625
> >>> 0x99 / 0x100
>0.59765625
> >>> 0x9 / 0x10
>0.5625
> >>> 0x900 / 0x1000
>0.5625
> >>> 0x999 / 0x1000
>0.599853515625
>
>Or a simpler proof: 0x8 is half of 0x10, and 0x80 is half of 0x100, while
>0x88 is slightly more than half.

But the scale of the colours span from all zeroes to all ones,
i.e. 0000 to 1111, or 00000000 to 11111111 etc, NOT from 00000
to 10000 etc.

 >>> from __future__ import division
 >>> 0x9/0xf
0.59999999999999998
 >>> 0x99/0xff
0.59999999999999998
 >>> 0x9999/0xffff
0.59999999999999998

All the same...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se