In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Primary Hues Spectrum

Roll  your mouse over the hue to get the hex.

I know there are ways to do with sinwaves and such; yet, this way, for me at least, is pretty easy to understand in my opinion. 

Of course, since this was a hack I put together pretty quickly, it's not  very modular.  Let me know if I am doing something wrong, if you think there is a better way..or if I should have labeled something differently.
Get Adobe Flash player
by NME 12 Sep 2013
//I know there are ways to do with sinwaves and such; yet, this way
//for me at least, is pretty easy to understand in my opinion.
//
//Let me know if I am doing something wrong, or if you think there is a better way.
//or if I should have labeled something differently.


package {
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.geom.Rectangle;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public var tf:TextField;
        public var huesBMPContainer:Sprite,
                   huesBMP:Bitmap,
                   hues:Vector.<uint>;//this will be where we store the hues
        
        //these next few arrays will be used to keep things in one loop
        //which is not necessary, and causes shift by 0, but it has its uses.
        public var mainHues:Array= [0xff0000,0x00ff00,0x00ff00,0x0000ff,0x0000ff,0xff0000],
                   from:Array = [  0, 254,   1, 254,   1, 254],//min or max  start values for loop
                   to:Array =   [256,  -1, 256,  -1, 256,   0],//max or min end values for loop
                   pom:Array =  [  1,  -1,   1,  -1,   1,  -1], //plus or minus... to increment or decrement in the for loop
                   shifts:Array = [8,16,0,8,16,0]; //amount to left shift << a number by
        
        public function getHueSpectrum():Vector.<uint>{
            var hues:Vector.<uint> = new Vector.<uint>;
            var huePos:uint = 0;
            var mhl:uint = mainHues.length;
            //place holders for an element from each of the 5 arrays
            var m:uint,f:uint,t:int,s:uint,p:int;
            //iteration variables
            var j:int,i:int=0;
            for(;i!=mhl;i+=1){
                f = from[i];
                t = to[i];
                p = pom[i];
                s = shifts[i];
                m = mainHues[i];
                for(j=f; j!=t; j+=p){
                    hues[huePos] = m + (j<<s);
                    huePos+=1;
                }
            }
            return hues;
        } 
        public function FlashTest() {
            // write as3 code here...
            var sw:uint = 1530>>2;
            var bmd:BitmapData;
            var hueRect:Rectangle = new Rectangle(0,0,1,100);
            var hl_sw:uint;
            huesBMPContainer = new Sprite();
            huesBMP = new Bitmap(new BitmapData(sw,100,false,0x000000));
            bmd = huesBMP.bitmapData;
            hues = getHueSpectrum();
            hl_sw = int((hues.length/sw)+0.5);
            
            for (var i:uint=0; i!=sw; i++){
               hueRect.x+=1;
               bmd.fillRect(hueRect,hues[i*hl_sw]);
            }
            huesBMPContainer.addChild(huesBMP);
            stage.addChild(huesBMPContainer);
            
            tf = new TextField();
            tf.text = '0x000000';
            tf.width = tf.textWidth+4;
            tf.textColor = 0x000000;
            tf.x=(sw-tf.width)>>1;
            tf.y=(stage.stageHeight-tf.height)>>1;
            stage.addChild(tf);
            
            huesBMPContainer.addEventListener(MouseEvent.MOUSE_MOVE,mmEH);
         
        }
        public function rgb2HexString(p:uint):String{
                var r:uint =  p>>16;
                var g:uint = (p>>8)&0xff;
                var b:uint = p&0xff;
                var rs:String = (r > 0)?(r>15)?r.toString(16): '0'+ (r).toString(16):'00';
                var gs:String = (g > 0)?(g>15)?g.toString(16): '0'+ g.toString(16):'00';
                var bs:String = (b > 0)?(b>15)?b.toString(16): '0'+ b.toString(16):'00';
                return '0x'+rs+gs+bs;
        }
        public function mmEH(me:MouseEvent):void{
            if(me.target == huesBMPContainer){
                tf.text = rgb2HexString(huesBMP.bitmapData.getPixel((me.target.mouseX==me.target.width)?me.target.width-0.25:me.target.mouseX,me.target.mouseY));
            }
        }
        
    }
}