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

code on 2009-1-16

上から
Get Adobe Flash player
by zahir 17 Jan 2009
    Embed
//上から
package{
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.BlurFilter;
	import flash.utils.Timer;
	
	[SWF(width="400", height="400")] 

	public class ColorChip3D_lab extends Sprite{
		
		private const RADIUS:Number = 150;
		private const HEIGHT:Number = 150;
		
		private var Chip_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 timer:Timer;
		
		
		public function ColorChip3D_lab(){
			super();
			
			cont = new Sprite();
			this.addChild(cont);
			
			cont.x = 200;
			cont.y = 200;
			cont.z = 0;
			
			var i:int = 0; var j:int = 0; var k:int = 0;
			var lim:int = 6;
			var step:int = 0x33;
			
			/*
			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); }
				}
			}//*/
//*
for(j = 0; j<16; j++){ 
            var nn:int = j*0x11; 
            Chipsfactry2( nn <<16); 
            Chipsfactry2( nn <<8); 
            Chipsfactry2( nn ); 
             
            Chipsfactry2( nn <<16 | nn <<8) 
            Chipsfactry2( nn <<16 | nn) 
            Chipsfactry2( nn <<8 | nn) 
             
            Chipsfactry2( nn <<16 | nn <<8 | 255) 
            Chipsfactry2( nn <<16 | 255<<8 | nn) 
            Chipsfactry2( 255 <<16 | nn <<8 | nn) 
             
            Chipsfactry2( 255<<16 | nn<<8) 
            Chipsfactry2( 255<<16 | nn); 
             
            Chipsfactry2( nn<<16 | 255<<8); 
            Chipsfactry2( nn<<16 | 255<8); 
             
            Chipsfactry2(255 <<8 | nn); 
             
            Chipsfactry2(nn<< 8 | 255); 
            Chipsfactry2(nn<<16 | 255); 
            Chipsfactry2(nn<<16 | 255<<8 | 255); 
            Chipsfactry2(255<<16 | nn<<8 | 255); 
            Chipsfactry2( 255 << 16 | 255<<8 | nn) 
             
            Chipsfactry2(nn<<16 | nn<<8 | nn); 
        }//*/
			
			len = Chip_arr.length;
			for(i = 0;i<len;i++){ 
                Chip_arr[i].addEventListener(MouseEvent.ROLL_OVER, over); 
                Chip_arr[i].addEventListener(MouseEvent.MOUSE_OUT, out); 
            } 
			
			//-------------------------------------------------------
			timer = new Timer(16);
			timer.addEventListener(TimerEvent.TIMER , onTimer );
			timer.start();
		}
		
		private function Chipsfactry(rr:int , gg:int, bb:int):void{
			
			var lab:Object = this.RGBtoLAB(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;
			
			var chip:ChipObject = new ChipObject( 10, rr<<16 | gg<<8 | bb, L, a, b, rad, r, -h);
			
			chip.x = r * Math.sin(rad);
			chip.y = r * Math.cos(rad);
			chip.z = -h;
			
			cont.addChild(chip);
			Chip_arr.push(chip);
		}
private function Chipsfactry2(c:uint):void{
			
			var lab:Object = this.RGBtoLAB(c>>16, c>>8 &0xFF, c &0xFF);
			
			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;
			
			var chip:ChipObject = new ChipObject( 10, c, L, a, b, rad, r, -h);
			
			chip.x = r * Math.sin(rad);
			chip.y = r * Math.cos(rad);
			chip.z = -h;
			
			cont.addChild(chip);
			Chip_arr.push(chip);
		}
		
		private function onTimer(e:TimerEvent):void{
			var i:int = 0
			rot += speed % 360;
			addRot = Math.PI/180 * rot;
			
			for(i = 0; i< len; i++){ onSetPos( Chip_arr[i] );}
			sort();
		}
		
		private function onSetPos(obj:ChipObject):void{
			var rad:Number = obj.posRad + addRot;
			var r:Number = obj.posR;
			var h:Number = obj.posHeight;
			
			obj.x = r * Math.sin(rad);
			obj.y = r * Math.cos(rad);
			obj.z = h;
			
		}
		
		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;
		}
		
		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 X:Number = (0.412391 * rr + 0.357584 * gg + 0.180481 * bb )/255;
		var Y:Number = (0.212639 * rr + 0.715269 * gg + 0.072192 * bb )/255;
		var Z:Number = (0.019331 * rr + 0.119195 * gg + 0.950532 * bb )/255;
		
		var _x:Number = (X/X0);
		var _y:Number = (Y/Y0);
		var _z:Number = (Z/Z0);
		
		var fx:Number = _x > 0.008856 ?  Math.pow( _x, 0.333):(7.787 * _x)+ q;
		var fy:Number = _y > 0.008856 ?  Math.pow( _y, 0.333):(7.787 * _y)+ q;
		var fz:Number = _z > 0.008856 ?  Math.pow( _z, 0.333):(7.787 * _z)+ q;
		
		var L:Number = 116 * fy -16;
		var a:Number = 500 * (fx - fy);
		var b:Number = 200 * (fy - fz);
		L = L<0 ? 0 : L;		
		return {"L":L, "a":a, "b":b};
	}
	}
	
}


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.beginFill(color);
		g.drawRect(-s,-s, s,s);
		g.endFill();
	}
}
import flash.display.*;
import flash.text.TextField;

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;
	}
	
}