Ben,

The reason that the values between do not fall into shades of grey is
because the decimal values you have that represent those colors are just
straight conversions from Hexadecimal to Decimal and therefore don't provide
anything meaningful.  To get true shades of grey you basically need each
group of values to represent the two next to them.  I'll try to do a
conversion for you so you might get an idea of how to do this on your own:

0x232323 if we break that into bits we get: 0010 0011 0010 0011 0010 0011. A
way you could do this is just get two random values from 0 - 15.

var i:Number = Math.random( 0, 15 );
var j:Number = Math.random( 0, 15 );
var randomGrey:Number = ( i << 20 ) | ( j << 16 ) | ( i << 12 ) | ( j << 8 )
| ( i << 4 ) | j;

I haven't tested this at all, I'm just kind of writing it out, but give it a
go and it should get you in the right direction.

Patrick Driggett

On 9/12/07, ben.clinkinbeard <[EMAIL PROTECTED]> wrote:
>
>   OK, my hex and bitwise skills are non-existent, so I am probably on
> the completely wrong track here, but... I converted a couple of hex
> values to decimal values (11776947 and 10724259) with an online
> converter. They each evaluate to a shade of gray (as expected), but
> when I generate random values that fall between the two and use them
> in the drawing API they are not shades of gray. I'm sure plenty of you
> are saying "duh", but if you could also suggest a way to randomly
> generate differing shades of gray I would be most appreciative.
>
> I suppose the chances of someone having written a RandomGrayGenerator
> class is pretty slim, so I am open to more general courses of action
> as necessary.
>
> Thanks,
> Ben
>
>  
>

Reply via email to