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

Pixel3D【練習】

Pixel3D練習
* clickでrandom配置
* 参考:http://wonderfl.net/code/c0f513f31389ba07e375331256c2bfa3a8b9006c
Get Adobe Flash player
by Nyarineko 13 Oct 2009
/**
 * Copyright Nyarineko ( http://wonderfl.net/user/Nyarineko )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/9vbk
 */

/*
* Pixel3D練習
* clickでrandom配置
* 参考:http://wonderfl.net/code/c0f513f31389ba07e375331256c2bfa3a8b9006c
*/
package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
    import flash.filters.BlurFilter;
	import flash.display.PixelSnapping;
    import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.geom.Matrix;
    import flash.geom.ColorTransform;
    import flash.geom.Rectangle;
    import flash.geom.Point;
	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;

	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="40")]
	public class Main extends BasicView{
	    private const RECT:Rectangle = new Rectangle(0, 0, 465, 465);
        private const ZEROS:Point = new Point(0, 0);
		private var _pixels:Pixels;
		private var _canvas:BitmapData;
        private var _head:Particle;
        private var _blurFilter:BlurFilter;
        private var _colorTransForm:ColorTransform;
        private var _mode:Number;
		
		private var mtx:Matrix;

		public function Main()
		{
			super(0, 0, true, true);
			var layer:BitmapEffectLayer=new BitmapEffectLayer(viewport, 465, 465, true, 0, BitmapClearMode.CLEAR_PRE, true);
			layer.clearBeforeRender=true;
			viewport.containerSprite.addLayer(layer);

			camera.z=-800;
			camera.y=100;
			
			_pixels=new Pixels(layer);
			scene.addChild(_pixels);
			
            var p:Particle = _head = new Particle();
			
            for (var i:uint = 0; i < 5000; ++i){
                p = p.next = new Particle();
            }
			
			_canvas=new BitmapData(465 / 4, 465 / 4, false, 0x000000);
			var bmp:Bitmap=new Bitmap(_canvas, PixelSnapping.NEVER, true);
			bmp.scaleX=bmp.scaleY=4;
			bmp.smoothing=true;
			bmp.blendMode=BlendMode.ADD;
			addChild(bmp);
            _blurFilter = new BlurFilter(2, 2, 1);
            _colorTransForm = new ColorTransform(0.95, 0.95, 0.95);
			mtx = new Matrix(0.25, 0, 0, 0.25);
			startRendering();
			addEventListener(Event.ENTER_FRAME, onFrame);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, _down);
            stage.addEventListener(MouseEvent.MOUSE_UP, _up);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, _move);
            _iniset();
		}
		
        private function _iniset(e:MouseEvent = null):void{
            var p:Particle = _head;
            var i:Number = 1;
            do {
				p.angle = i;
				p.radius = i / 11;
				p.setPixel3D();
				_pixels.addPixel3D(p.pix3d);
				_pixels.y = 350;
                i ++;
            } while (p = p.next);
		}
        private function _down(e:MouseEvent = null):void{
            var p:Particle = _head;
            var i:Number = 1;
			do {
				p.angle = p.angle + p.angle * Math.random();;
				i ++;
			} while (p = p.next);
        }
        private function _up(e:MouseEvent = null):void{
            var p:Particle = _head;
            var i:Number = 1;
			do {
				p.angle = i;
				i ++;
			} while (p = p.next);
        }
        private function _move(e:MouseEvent = null):void{
			camera.x = mouseX - 230;
			camera.y = mouseY - 130;
		}

		private function onFrame(e:Event):void
		{
            var p:Particle = _head;
            var i:Number = 1;
            do {
				p.angle++;
				p.pix3d.x=(p.radius * Math.cos(p.angle * Math.PI / 180));
				p.pix3d.y= -(i / 10);
				p.pix3d.z=(p.radius * Math.sin(p.angle * Math.PI / 180));
                i ++;
            } while (p = p.next);
			
            _canvas.lock();
			_canvas.fillRect(_canvas.rect, 0x000000);
			_canvas.draw(viewport, mtx);
            _canvas.applyFilter(_canvas, RECT, ZEROS, _blurFilter);
			_canvas.colorTransform(RECT, _colorTransForm);
            _canvas.draw(_canvas, null, null, BlendMode.ADD);
            _canvas.unlock();
			//_pixels.rotationY+=1;
		}
	}
}
	

internal class Particle {
	import org.papervision3d.core.geom.renderables.Pixel3D;
	public var radius:Number;
	public var angle:Number;
	public var xx:Number = 0;
	public var yy:Number = 0;
	public var zz:Number = 0;
	public var pix3d:Pixel3D;
	public var next:Particle;
		public function setPixel3D():void
		{
			pix3d=new Pixel3D((0xff << 24 | 0xff * Math.random() << 16 | 0xff << 8 | 0xff * Math.random() ), xx, yy, zz);
		}
}