color test

by Nos_lkSsvOhB
♥0 | Line 82 | Modified 2013-08-20 08:19:21 | MIT License
play

ActionScript3 source code

/**
 * Copyright Nos_lkSsvOhB ( http://wonderfl.net/user/Nos_lkSsvOhB )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/qtiW
 */

package {
    import flash.display.*;
    import flash.events.*;
    public class FlashTest extends Sprite {
        private var w:int=465;
        private var h:int=465;
        private var hh:int=250;
        private var xoff:Number=465/2;
        private var yoff:Number=465/2;
        private var w_c:int=465;
        private var h_c:int=465;
        private var n:int=64;
        private var eps:Number=Math.pow(10,-13);
        private var thi:Number=Math.PI/(n+1);
        private var th:Number=thi;
        private var hn:Number=360/(2*n+1);
        private var yx0:Number;
        private var yx1:Number;

        private var hi:Number;
        private var ho:Number;
        private var f:Number;
        private var p:Number;
        private var q:Number;
        private var t:Number;
        private var re:Number;
        
        public function FlashTest() {
            var stg:Sprite=new Sprite();
            addChild(stg);
            with(stg.graphics){
                lineStyle(1,0x000000,1);
                moveTo(xoff-w_c/2,yoff+0);
                lineTo(xoff+w_c/2,yoff+0);
                moveTo(xoff+0,yoff-h_c/2);
                lineTo(xoff+0,yoff+h_c/2);
            }

            for(var i:int=0;i<2*n+1;i++){
                if((th<Math.PI/2-eps || th>Math.PI/2+eps) && (th<Math.PI-eps || th>Math.PI+eps) && (th<3*Math.PI/2-eps || th>3*Math.PI/2+eps)){
                    stg.graphics.lineStyle(1,hsv_rgb(hn*i,255,255),1);
                    yx0=-Math.tan(th)*w/2+h_f(th);
                    yx1=Math.tan(th)*w/2+h_f(th);
            
                    stg.graphics.moveTo(xoff-w/2,yoff+yx0);
                    stg.graphics.lineTo(xoff+w/2,yoff+yx1);
                    stg.graphics.moveTo(xoff-w/2,yoff+yx0);
                    stg.graphics.lineTo(xoff+w/2,yoff+yx1);
            
                }
                th+=thi;
            }
        }            
        
        //th 0~2pi
        private function h_f(th:Number):Number{
            hi=hh/2*Math.sin(th);
            return hi;
        }
            
        //hue 0~360, sat 0~255, val 0~255
        private function hsv_rgb(hue:Number,sat:Number,val:Number):Number{
            ho = int(hue / 60) % 6;
            f = (hue / 60) - ho;
            p = Math.round(val * (1 - (sat / 255)));
            q = Math.round(val * (1 - (sat / 255) * f));
            t = Math.round(val * (1 - (sat / 255) * (1 - f)));
                   
            if(ho==0){
                re=val*Math.pow(16,4)+t*Math.pow(16,2)+p;
                return re;
            }else if(ho==1){
                re=q*Math.pow(16,4)+val*Math.pow(16,2)+p;
                return re;
            }else if(ho==2){
                re=p*Math.pow(16,4)+val*Math.pow(16,2)+t;
                return re;
            }else if(ho==3){
                re=p*Math.pow(16,4)+q*Math.pow(16,2)+val;
                return re;
            }else if(ho==4){
                re=t*Math.pow(16,4)+p*Math.pow(16,2)+val;
                return re;
            }else if(ho==5){
                re=val*Math.pow(16,4)+p*Math.pow(16,2)+q;
                return re;
            }else{
                return 0;
            }
        }
    }
}