7 Replies Latest reply on May 10, 2006 4:18 AM by Hakan KIRIK

# generating a different color

I'm trying to make an application that can make a square or whatever change color but is has to start from 0x000000 and end in 0xFFFFFF. How would I make it go through all the possibilities?
var hexArray:Array = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];

I made this array for a start but I can't figger out how to right the code.
• ###### 1. generating a different color
I wont pretend to know this one but by the looks of it, its one hell of a calculation with it being "to the power of". You might want to consider looking at the problem for a different angle.

Take a look at this file to see what I mean

http://www.flashkit.com/movies/Interfaces/Widgets/Colour_P-Richard_-46/index.php
• ###### 2. Re: generating a different color
yeah well the problem there is that I doesn't go through the possibilities.

I have to have that.
And there are over 16 million combinations. That I know too.
I've been thinking of first generating from 00 to FF for red, green and blue seperatly. And then making it into one color. Then I could use the same function for all 3 of them but I still don't know exacly how I would know that I'm going through all the possibilities

• ###### 4. Re: generating a different color
no , thx alot DazFaz but Its not what I'm looking for.

I've been thinking of running a for(i=0;i<16777316;i++)
and dividing i%16 so I constantly run from 0 to 15
now all I need it to know when to go the the next digit in the color like :0x100000 to 0xF00000 then 0x0100000
and so on.
• ###### 5. Re: generating a different color
not sure what exactly you're looking for. anyway, you can get the hex
value from primary color values shifting & adding (bitwise)

hex = r << 16 | g << 8 | b

DrEv1l wrote:

> no , thx alot DazFaz but Its not what I'm looking for.
>
> I've been thinking of running a for(i=0;i<16777316;i++)
> and dividing i%16 so I constantly run from 0 to 15
> now all I need it to know when to go the the next digit in the color like
> :0x100000 to 0xF00000 then 0x0100000
> and so on.
>
• ###### 6. Re: generating a different color
well what i need is some way to run through all the RGB colors in flash.
form 0x000000 tot 0xFFFFFF. Will that shifting and adding help, if so could you explain further?

thx
• ###### 7. Re: generating a different color

Hi ,
look at my code, maybe it gives an idea...

Hakan K.
www.FlashDersi.com

var renk:Color = new Color(mc1);
var rr;
var bb;
var yy;
rr = 255;
bb = 255;
yy = 255;
var step;
step = 80;//change this
onEnterFrame = function () {
if (yy>0) {
//trace(rr)
renk.setRGB(rr << 16 | bb << 8 | yy);
yy -= step;
} else {
yy = 0;
if (bb>0) {
yy = 255;
bb -= step;
} else {
bb = 0;
if (rr>0) {
yy = 255;
bb = 255;
rr -= step;
} else {
rr = 0;
delete onEnterFrame;
}
}
}renk.setRGB(rr << 16 | bb << 8 | yy)
trace("rr: "+rr+" - bb: "+bb+" - yy: "+yy);
};