That should probably be:

 

Var myGreys:Array = [...];

 

The example code I gave you just showed how to interpolate between two
specific values. I'm assuming that in your code, you've got lots of grey
values, and rules for deciding which two ones you want to interpolate
between.  So You can generalize the code to first decide what the two
values you're using are, and then run the code below.  i.e., I could
have written it as:

 

Var greyOne:uint = 0x38;

Var greyTwo:uint = 0xE3;

 

var newGreyByte:uint = ((greyOne + (greyTwo  - greyOne) *
Math.random()) as uint);



Ely.

 

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of ben.clinkinbeard
Sent: Wednesday, September 12, 2007 11:22 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: How do I generate random colors (within a
range)?

 

Hi Ely,

I (mostly) understand the concept in your example but am getting an
error that I can't figure out for the life of me. On the line where
you assign newGreyByte its telling me "1084: Syntax error: expecting
rightparen before myGreys.".

Also, shouldn't myGreys[2] be utilized somewhere?

Thanks,
Ben

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
, "Ely Greenfield" <[EMAIL PROTECTED]> wrote:
>
> 
> 
> 
> 
> Grey RGB values have the same byte value in each of the rbg channels.
> So your best bet is to store your grey values as single byte hex
values
> 
> 
> 
> myGreys = [0xAA, 0x58, 0x22];
> 
> 
> 
> then interpolate between those values:
> 
> 
> 
> var newGreyByte:uint = ((myGreys[0] + (myGreys[1] - myGreys[0]) *
> Math.random()) as uint);
> 
> 
> 
> Then create an rgb value out if that:
> 
> 
> 
> var newGreyRGB:uint = (newGreyByte << 16) + (newGreyByte << 8) +
> newGreyByte;
> 
> 
> 
> Ely.
> 
> 
> 
> 
> 
> From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
[mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of ben.clinkinbeard
> Sent: Wednesday, September 12, 2007 9:59 AM
> To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] How do I generate random colors (within a
range)?
> 
> 
> 
> 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
>

 

<<image001.jpg>>

<<image002.jpg>>

Reply via email to