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

とりあえず動かせるようにしてみた

ソース汚いです
Get Adobe Flash player
by zahir 30 Jan 2009
    Embed
/*
	ソース汚いです
*/
package{ 
    import flash.display.*;
    import flash.events.*;
    import flash.geom.Matrix3D;
    import flash.geom.Vector3D;
    import flash.text.*; 
     
    //[SWF(width="400", height="400")]  

    public class ColorChip3D_lab extends Sprite{ 
         
        private var RADIUS:Number = 200; 
        private var HEIGHT:Number = 100; 
        private var hh:Number = HEIGHT/2;
         
        private var Chip_arr:Array = new Array(); 
        private var mtx_arr:Array = new Array();
        private var len:int = 0; 
         
        private var speed:Number = .2; 
        private var rot:Number = 0; 
        private var addRot:Number = 0; 
         
        private var cont:Sprite; 
        private var tt:ToolChip; 
        
        private var csX:CircleSlider;
        private var csY:CircleSlider;
        private var csZ:CircleSlider;
        
        private var lsRAD:LineSlider;
        private var lsHEIGHT:LineSlider;
         
        public function ColorChip3D_lab(){ 
            super(); 
             
            cont = new Sprite(); 
            this.addChild(cont); 
             
            cont.x = this.stage.stageWidth/2; 
            cont.y = this.stage.stageHeight/2; 
            cont.z = 0; 
             
            var i:int = 0; var j:int = 0; var k:int = 0; 
            var lim:int = 6; 
            var step:int = 0x33;
            
            
            var sliderCont:Sprite = new Sprite();
            var tfLS:TextField = new TextField();
            tfLS.text = "半径:" + "\n\n" + "高さ:"
            tfLS.selectable = false;
            tfLS.width = 30;
            
            
            csX = new CircleSlider("X", this , 0x8899FF, 0.8, 0x556699);
            sliderCont.addChild(csX);
            csY = new CircleSlider("Y", this, 0x66CC66, 0.8, 0x336633);
            sliderCont.addChild(csY);
            csY.x = sliderCont.width + 5;
            csZ = new CircleSlider("Z", this, 0xFF8899, 0.8, 0x993333);
            sliderCont.addChild(csZ);
            csZ.x = sliderCont.width + 5;
            
            tfLS.x = sliderCont.width + 30;
            tfLS.y = 8;
            
            
            var oldw:int = sliderCont.width + 63;
            lsRAD = new LineSlider("半径", this, 120);
            sliderCont.addChild(lsRAD);
            
            lsRAD.x = oldw;
            lsRAD.y = 15;
            
            lsHEIGHT = new LineSlider("半径", this, 120);
            sliderCont.addChild(lsHEIGHT);
            lsHEIGHT.x = oldw;
            lsHEIGHT.y = 45;
            
            sliderCont.addChild(tfLS);
            
             
            //* 
            for(i=0; i<lim; i++){ 
                for(j=0; j<lim; j++){ 
                    for(k=0; k<lim; k++){ Chipsfactry(i*step, j*step, k*step); } 
                } 
            }//*/ 
            len = Chip_arr.length; 
            for(i = 0;i<len;i++){
            	mtx_arr.push( Chip_arr[i].transform.matrix3D.clone());
                Chip_arr[i].addEventListener(MouseEvent.ROLL_OVER, over);  
                Chip_arr[i].addEventListener(MouseEvent.MOUSE_OUT, out);  
            }  
            sort();
            
            this.addChild(sliderCont);
        } 
         
        private function Chipsfactry(rr:int , gg:int, bb:int):void{ 
             
            var lab:Object = this.RGBtoLAB2(rr, gg, bb); 
             
            var L:Number = lab.L; 
            var a:Number = lab.a; 
            var b:Number = lab.b; 
             
            var rad:Number = Math.atan2(a,b); 
            var r:Number = Math.sqrt( (a*a) + (b*b)); 
            var h:Number = L * HEIGHT; 
             
            var chip:ChipObject = new ChipObject( 8, rr<<16 | gg<<8 | bb, lab._L, lab._a, lab._b, rad, r, -h); 
            r *= RADIUS;
            
            chip.x = (r) * Math.sin(rad); 
            chip.y = -h + hh; 
            chip.z = (r) * Math.cos(rad); 
             
            cont.addChild(chip); 
            Chip_arr.push(chip); 
        } 
        private function sort():void{ 
            var z_arr:Array = new Array(); 
            for(var i:int = 0;i< len; i++){ z_arr.push({ "depth":Chip_arr[i].z, "obj":Chip_arr[i]});} 
            z_arr.sortOn("depth", Array.NUMERIC | Array.DESCENDING); 
            for(i = 0; i < len; i++){ cont.setChildIndex(z_arr[i].obj,i);} 
            z_arr= null; 
        }
        
        public function onChange():void{
        	var radLen:Number =lsRAD.value * RADIUS;
        	var heigtLen:Number = lsHEIGHT.value * HEIGHT;
        	for(var i:int = 0; i< len; i++){ onChangePos( Chip_arr[i], mtx_arr[i] ,{X:csX.value, Y:csY.value, Z:csZ.value},radLen,heigtLen);}
        	sort();
        }
        private function onChangePos(obj:ChipObject, _mtx:Matrix3D, rot:Object , rad:Number, h:Number):void{
        	var m:Matrix3D = new Matrix3D();
        	
        	obj.transform.matrix3D.identity();
        	obj.transform.matrix3D.append(_mtx);
        	
            m.appendTranslation((obj.posR*rad) * Math.sin(obj.posRad), -obj.L/100 * h ,(obj.posR*rad) * Math.cos(obj.posRad)); 
            m.appendTranslation(0, h/2, 0); 
        	m.appendRotation(rot.X, new Vector3D(1,0,0));
        	m.appendRotation(rot.Y, new Vector3D(0,1,0));
        	m.appendRotation(rot.Z, new Vector3D(0,0,1));
        	
        	obj.transform.matrix3D.append(m);
        	obj.rotationX -= rot.X;
        	obj.rotationY -= rot.Y;
        	obj.rotationZ -= rot.Z;
        } 
         
        private function over(e:MouseEvent):void{ 
            tt = new ToolChip(e.target.COLOR, e.target.L, e.target.a, e.target.b); 
            tt.x = this.stage.mouseX + 10; 
            tt.y = this.stage.mouseY + 10; 
            this.addChild(tt); 
        } 
        private function out(e:MouseEvent):void{ this.removeChild(tt);} 
         
        private const X0:Number = 0.95045; 
        private const Y0:Number = 1.0; 
        private const Z0:Number = 1.08892; 
        /* 
            L:[0~100]  
            a:[-134~220] 
            b:[-140~122] 
        */ 
        private const q:Number = 16/116; 
		private function RGBtoLAB(rr:int, gg:int, bb:int):Object{ 
		    var n:Number = 16/116;
			
		    var X:Number = (rr * 0.6070 + gg * 0.1740 + bb * 0.200)/255;
		    var Y:Number = (rr * 0.2990 + gg * 0.5870 + bb * 0.144)/255;
		    var Z:Number = (rr * 0.0000 + gg * 0.0660 + bb * 1.112)/255;
			
		    var _x:Number =  X / 0.98072;
		    var _y:Number =  Y;
		    var _z:Number =  Z / 1.18255;
			
		    _x = _x > 0.008856 ? Math.pow( _x, 0.333) : 7.787 * _x + n;
		    _y = _y > 0.008856 ? Math.pow( _y, 0.333) : 7.787 * _y + n;
		    _z = _z > 0.008856 ? Math.pow( _z, 0.333) : 7.787 * _z + n;
			
		    var L:Number = 116 * _y -16;
		    var a:Number = 504.3 * (_x - _y);
		    var b:Number = 201.7 * (_y - _z);
			
		    return {"L":L, "a":a, "b":b}
		}
		/*
			L:[0.0~1.0]  
            a:[-1.0~1.0] 
            b:[-1.0~1.0] 
		*/
		private function RGBtoLAB2(rr:int, gg:int, bb:int):Object{
			var lab:Object = RGBtoLAB(rr, gg, bb);
			var L:Number = lab.L / 100;
			var a:Number = lab.a < 0 ? lab.a / 134 : lab.a / 220;
			var b:Number = lab.b < 0 ? lab.b / 140 : lab.b / 122;
			return {"L":L, "a":a, "b":b, "_L":lab.L, "_a":lab.a, "_b":lab.b};
		}
    } 
}
import flash.display.*;
class CircleSlider extends Sprite{
	private var g:Graphics;
	private var cx:int, cy:int;
	
	public var value:Number = 0;
	private var s:Sprite;
	private var myParent:ColorChip3D_lab;
	private var pi:Number = Math.PI / 180;
	
	public function CircleSlider(str:String="_", _parent:ColorChip3D_lab = null,
									fill:uint=0xCCCCCC, Aa:Number= 0.9, stroke:uint=0x666666){
		cx = cy = 35;
		g = this.graphics;
		g.lineStyle(0, stroke);
		g.beginFill(fill, Aa);
		g.drawCircle(cx, cy, 25);
		g.drawCircle(cx, cy, 15);
		g.endFill();
		
		s = new Sprite();
		g = s.graphics;
		g.lineStyle(0, stroke);
		g.beginFill( 0xFFFFFF, .8 );
		g.drawCircle(0, 0, 5);
		g.endFill();
		this.addChild(s);
		
		s.x = Math.cos( pi * 0 ) * 20 + cx;
		s.y = Math.sin( pi * 0 ) * 20 + cy;
		
		s.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
		
		myParent = _parent;
	}
	private function onDown(e:MouseEvent):void{
		this.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
		this.stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
	}
	private function onMove(e:MouseEvent):void{
		value = Math.atan2(this.mouseY - cy, this.mouseX - cx);
		s.x = Math.cos( value ) * 20 + cx;
		s.y = Math.sin( value ) * 20 + cy;
		
		value = value / Math.PI * 180;
		myParent.onChange();
	}
	private function onUp(e:MouseEvent):void{
		this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
		this.stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
	}
}

class LineSlider extends Sprite{
	private var g:Graphics;
	private var s:Sprite;
	private var w:int;
	private var hw:int;
	private var myParent:ColorChip3D_lab;
	
	public var value:Number = 0; // -1~1
	
	public function LineSlider(str:String="_", _parent:ColorChip3D_lab = null, _w:int = 100,
									fill:uint=0xCCCCCC, Aa:Number= 0.9, stroke:uint=0x666666){
		w = _w;
		hw = w/2;
		
		g = this.graphics;
		g.lineStyle(0, stroke);
		g.beginFill( fill, Aa);
		g.drawRect(0,0,w,5);
		g.endFill();
		
		s = new Sprite();
		g = s.graphics;
		g.lineStyle(0, stroke);
		g.beginFill( fill, Aa);
		g.drawRect(-3,-5,6,15);
		g.endFill();
		this.addChild(s);
		s.x = w/2;
		s.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
		
		myParent = _parent;
	}
	private function onDown(e:MouseEvent):void{
		this.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
		this.stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
	}
	private function onMove(e:MouseEvent):void{
		s.x = 0>this.mouseX ? 0: w<this.mouseX ? w:this.mouseX;
		
		value = (s.x - hw) / hw;
		myParent.onChange();
	}
	private function onUp(e:MouseEvent):void{
		this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
		this.stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
	}
}

import flash.display.*; 
class ChipObject extends Sprite{ 
     
    public var COLOR:uint; 
    public var L:Number; 
    public var a:Number; 
    public var b:Number; 
     
    public var posRad:Number; 
    public var posR:Number; 
    public var posHeight:Number; 
     
    public function ChipObject(size:int, color:uint, _L:Number, _a:Number, _b:Number, 
                                rad:Number, r:Number, h:Number){ 
        super(); 
         
        COLOR = color; 
         
        L = _L; 
        a = _a; 
        b = _b; 
         
        posRad = rad; 
        posR = r; 
        posHeight = h; 
         
        var s:Number = size/2; 
        var g:Graphics = this.graphics; 
        g.lineStyle(0, 0x666666, 0.3); 
        g.beginFill(color); 
        g.drawRect(-s,-s, size,size); 
        g.endFill(); 
    } 
} 
import flash.display.*; 
import flash.text.TextField;
import flash.events.MouseEvent; 

class ToolChip extends Sprite{ 
    public function ToolChip(color:uint, l:int, a:int, b:int){ 
        super(); 
        var g:Graphics = this.graphics; 
        g.lineStyle(0,8421504,0.5); 
        g.beginFill((255<<16) | (255<<8) | 255,0.9); 
        g.drawRect(0,0,65,75); 
        g.endFill(); 
         
        var tf:TextField = new TextField(); 
        this.addChild(tf); 
         
        var _txt:String = color.toString(16) + "\n" + "L:"+ l + "\n" + "a:"+ a + "\n" + "b:"+ b + "\n"; 
        tf.text = _txt; 
        tf.height = 110 
        tf.x = 5 
        tf.y = 5; 
    } 
}