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

forked from: PV3Dその8 Pixels使ってみる

久々のPV3D。
やっぱASは打ってて楽しい。

zahirです。
面白そうだったのでforckedさせていただきました。
とりあえず、画像を読み込んでHLS色空間にPixel3Dでプロット
ps.黒が中心になってたのを修正.
// forked from sake's PV3Dその8 Pixels使ってみる
/*
   久々のPV3D。
   やっぱASは打ってて楽しい。
*/
/*
	zahirです。
	面白そうだったのでforckedさせていただきました。
    とりあえず、画像を読み込んでHLS色空間にPixel3Dでプロット
    ps.黒が中心になってたのを修正.
*/
package
{
	
	import __AS3__.vec.Vector;
	
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.ShaderJob;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.ShaderEvent;
	import flash.geom.Matrix;
	import flash.net.FileFilter;
	import flash.net.FileReference;
	
	[SWF(width="465", height="465", frameRate="30", backgroundColor="0x999999")]

	public class PV3D_pixels extends Sprite
	{
		private var fr:FileReference;
		 
		public function PV3D_pixels()
		{
			
			//キャプチャ
			Wonderfl.capture_delay(20);
			
			var btn:Btn = new Btn(200,20,"LOAD(JPEG, PNG, GIF)");
			addChild( btn );
			btn.addEventListener(MouseEvent.CLICK,function(e:MouseEvent):void{
				fr = new FileReference();
				fr.addEventListener(Event.SELECT, onSelect);
				fr.addEventListener(Event.COMPLETE, onComp);
				fr.browse( [ new FileFilter( "Images", "*.jpg;*.gif;*.png" ) ] );
			});
		}
		private function onSelect(e:Event ):void{
			fr.load();
		}
		private function onComp(e:Event):void{
			var l:Loader = new Loader();
			l.contentLoaderInfo.addEventListener(Event.INIT, function(e:Event):void{
				
				const lim:int = 200; // このサイズに画像を縮める
				if(l.width >= l.height) l.width = lim, l.scaleY = l.scaleX;
				else if(l.height >l.width) l.height = lim, l.scaleX = l.scaleY;
				var m:Matrix = new Matrix();
				m.scale( l.scaleX, l.scaleY );
				var bd:BitmapData = new BitmapData(l.width, l.height);
				bd.draw( l, m);
				
				var s:RGBtoHLS_3D = new RGBtoHLS_3D();
				s.allStter( bd, bd.width, bd.height, [300],[0,0,0], [300]);
				
				var v:Vector.<Number> = new Vector.<Number>();
				var sj:ShaderJob = new ShaderJob( s, v, bd.width, bd.height );
				sj.start();
				sj.addEventListener(ShaderEvent.COMPLETE, function(e:ShaderEvent):void{
					addChild( new View( v ) );
				});
				/*
				var bmp:Bitmap = new Bitmap(bd);
				bmp.y = 25;
				addChild( bmp );
				//*/
			});
			l.loadBytes( fr.data );
		}
		
	}
}

import __AS3__.vec.Vector;
import flash.display.Graphics;
import flash.display.Shader;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

import mx.utils.Base64Decoder;

import org.papervision3d.core.effects.BitmapLayerEffect;
import org.papervision3d.core.effects.utils.BitmapClearMode;
import org.papervision3d.core.geom.Pixels;
import org.papervision3d.core.geom.renderables.Pixel3D;
import org.papervision3d.view.BasicView;
import org.papervision3d.view.layer.BitmapEffectLayer;


class View extends BasicView{
	
	private var pixels:Pixels; 
	private var rotateX:Number; 
	private var rotateY:Number;
	
	public function View( v:Vector.<Number> ):void{
		super(0, 0,true, true);
		
		var layer:BitmapEffectLayer=new BitmapEffectLayer(viewport, 465, 465, false, 0, BitmapClearMode.CLEAR_PRE, true); 
		viewport.containerSprite.addLayer(layer); 
		layer.addEffect(new BitmapLayerEffect(new BlurFilter(16, 16, 4), false)); 
		camera.z=-500; 
		rotateX=rotateY=0;
		pixels = new Pixels(layer); 
		scene.addChild(pixels); 
		
		var len:int = v.length;
		for(var i:int=0; i<len; i+=4){
			pixels.addPixel3D( new Pixel3D( v[i+3], v[i], v[i+1], v[i+2] ) );
		}
		
		addEventListener(Event.ENTER_FRAME, onFrame);
	}
	private function onFrame(e:Event):void{
		rotateX+=(-viewport.containerSprite.mouseX - rotateX) * 0.1; 
		rotateY+=(-viewport.containerSprite.mouseY - rotateY) * 0.1; 
		pixels.rotationY=rotateX; 
		pixels.rotationX=rotateY; 
		startRendering();
	}
}
class Btn extends Sprite{
	public function Btn(width:int, height:int, label:String):void{
		var g:Graphics = graphics;
		g.lineStyle(1, 0);
		g.beginFill(0x111111);
		g.drawRect(0,0, width, height);
		g.endFill();
		
		var t:TextField = new TextField();
		t.defaultTextFormat = new TextFormat( "_typeWriter", 17);
		t.text = label;
		t.textColor = 0xCCCCCC;
		t.autoSize = TextFieldAutoSize.LEFT;
		addChild(t);
	}
}


class RGBtoHLS_3D extends Shader{
	public function RGBtoHLS_3D(){
		var dec:Base64Decoder = new Base64Decoder();
		dec.decode( "pQEAAACkCwBSR0J0b0hMU18zRKAMbmFtZXNwYWNlAHphaGlyMTkyOQCgDHZlbmRvcgB6YWhpcgCgCHZlcnNpb24AAQCgDGRlc2NyaXB0aW9uAFJHQnRvSExTKEg6OjB+MzYwLCBTOjowfjEwMCwgTDo6MH4xMDApAKEBAgAADF9PdXRDb29yZACjAANzcmMAoQIEAQAPZHN0AKEBAQAAAlJBRElVUwCiAW1heFZhbHVlAEPIAACiAW1pblZhbHVlAD+AAACiAWRlZmF1bHRWYWx1ZQBDFgAAoQEBAAABSEVJR0hUAKIBbWF4VmFsdWUAQ8gAAKIBbWluVmFsdWUAP4AAAKIBZGVmYXVsdFZhbHVlAEMWAAChAQMCAA5wb3MAogNtYXhWYWx1ZQBDyAAAQ8gAAEPIAACiA21pblZhbHVlAMPIAADDyAAAw8gAAKIDZGVmYXVsdFZhbHVlAAAAAAAAAAAAAAAAADADAOEAABAAHQQA4gMAGAAyAgAQQ38AAB0DAIAEAAAAAwMAgAIAwAAdAgAQAwAAADIDAIBDfwAAHQMAQAQAQAADAwBAAwAAAB0DAIADAEAAMgMAQEN/AAAdAwAgBACAAAMDACADAEAAHQMAQAMAgAAdAwAgAwAAAAoDACADAEAAHQMAEAIAwAAKAwAQAwCAAB0DACADAMAAHQMAEAMAA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B0JAEAIAEAAHQkAIAgAgAAdCQAQBwAAAB0BAPMJABsA" );
		byteCode = dec.toByteArray();
		dec = null;
	}
	public function allStter( _src:* = null, _srcWidth:int = 0, _srcHeight:int = 0, _HEIGHT:Array = null, _pos:Array = null, _RADIUS:Array = null ):void{
		data.src.input = _src;
		data.src.width = _srcWidth;
		data.src.height = _srcHeight;

		data.HEIGHT.value = _HEIGHT;
		data.pos.value = _pos;
		data.RADIUS.value = _RADIUS;

	}

/*------------------------------------------------
	Input's
------------------------------------------------*/

	/**
	 * Get src
	 * @return int [ 3 Channel ]
	 */
	public function get src():int{
		return data.src.channels;
	}

	/**
	 * Set src
	 */
	public function set src( src:* ):void{
		data.src.input = src;
	}

	/**
	 * Get src.width
	 * @return int
	 */
	public function get srcWidth():int{
		return data.src.width;
	}

	/**
	 * Set src.width
	 */
	public function set srcWidth( value:int ):void{
		data.src.width = value;
	}

	/**
	 * Get src.height
	 * @return int
	 */
	public function get srcHeight():int{
		return data.src.height;
	}

	/**
	 * Set src.height
	 */
	public function set srcHeight( value:int ):void{
		data.src.height = value;
	}


/*------------------------------------------------
	Parameter's
------------------------------------------------*/

	/**
	 * Get HEIGHT
	 * @return Array[ float ]
	*/
	public function get HEIGHT():Array{
		return data.HEIGHT.value;
	}
	/**
	 * Set HEIGHT
	 *
	 *  - name:[ HEIGHT ]
	 *  - maxValue:[ 400 ]
	 *  - minValue:[ 1 ]
	 *  - defaultValue:[ 150 ]
	 *
	 * @param value Array [ float ]
	*/
	public function set HEIGHT( value:Array ):void{
		data.HEIGHT.value = value;
	}

	/**
	 * Get pos
	 * @return Array[ float3 ]
	*/
	public function get pos():Array{
		return data.HEIGHT.value;
	}
	/**
	 * Set pos
	 *
	 *  - name:[ pos ]
	 *  - maxValue:[ 400,400,400 ]
	 *  - minValue:[ -400,-400,-400 ]
	 *  - defaultValue:[ 0,0,0 ]
	 *
	 * @param value Array [ float3 ]
	*/
	public function set pos( value:Array ):void{
		data.pos.value = value;
	}

	/**
	 * Get RADIUS
	 * @return Array[ float ]
	*/
	public function get RADIUS():Array{
		return data.HEIGHT.value;
	}
	/**
	 * Set RADIUS
	 *
	 *  - name:[ RADIUS ]
	 *  - maxValue:[ 400 ]
	 *  - minValue:[ 1 ]
	 *  - defaultValue:[ 150 ]
	 *
	 * @param value Array [ float ]
	*/
	public function set RADIUS( value:Array ):void{
		data.RADIUS.value = value;
	}
}