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

HLS3D

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 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(){
			super();
			
			cont = new Sprite();
			this.addChild(cont);
			
			cont.x = 200;
			cont.y = 250;
			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); }
				}
			}//*/
			
			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 hls:Object = this.RGBtoHLS(rr, gg, bb);
			
			var H:Number = hls.H;
			var L:Number = hls.L;
			var S:Number = hls.S;
			
			var rad:Number = 360-(2*Math.PI*Math.round(hls.H))/360;
			var r:Number = RADIUS * (hls.S/100);
			var h:Number = HEIGHT * (hls.L/100);
			
			var chip:ChipObject = new ChipObject( 14, rr<<16 | gg<<8 | bb, H, L, S, rad, r, -h);
			
			chip.x = r * Math.sin(rad);
			chip.y = -h;
			chip.z = r * Math.cos(rad);
			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 = h;
			obj.z = r * Math.cos(rad);
			// clockmakerさんの3D Carouselより
			var d:Number = obj.z/10;
			obj.filters = (d > 2) ? [new BlurFilter(d, d, 3)] : []   
		}
		
		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);}
		
		public function RGBtoHLS(rr:int , gg:int , bb:int):Object{
			
			var max:int = Math.max(rr,Math.max(gg,bb));
			var min:int = Math.min(rr,Math.min(gg,bb));
			
			var HUEMAX:int = 360;
			var RGBMAX:int = 255;
			var HLSMAX:int = 255;
			
			var H:Number = 0;
			var L:Number = (max+min)/2;
			var S:Number = 0;
			
			if(max == min)
				S = H =0;
			else{
				if( L >= 128)
					S = ((max-min)/(max+min))*L*0.785;
				else
					S = ((max-min)/(2*RGBMAX-max-min))*(255-L)*0.785;
			
				var Cr:Number = ( ((max-rr)*60) + ((max-min)/2) ) / (max-min);
				var Cg:Number = ( ((max-gg)*60) + ((max-min)/2) ) / (max-min);
				var Cb:Number = ( ((max-bb)*60) + ((max-min)/2) ) / (max-min);

			
				if(rr==max)
					H = Cb-Cg;
				else if(gg==max)
					H = 120+Cr-Cb;
				else
					H = 240+Cg-Cr;
				
				if (H < 0)
					H += 360;
				if (H > 360)
					H -= 360;
			}
			L = (L/255)*100;

			var obj:Object = {"H":H,"L":L,"S":S};
			return obj;
		}
	}
}


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

class ToolChip extends Sprite{
	public function ToolChip(color:uint, h:Number, l:int, s:int){
		super();
		var g:Graphics = this.graphics;
		g.lineStyle(0,8421504,0.5);
		g.beginFill(0xFFFFFF,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" + "H:"+ h + "\n" + "L:"+ l + "\n" + "S:"+ s + "\n";
		tf.text = _txt;
		tf.height = 110
		tf.x = 5
		tf.y = 5;
	}
}