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

by yasohachi forked from PV3Dその8 Pixels使ってみる (diff: 60)
久々のPV3D。
やっぱASは打ってて楽しい。
♥0 | Line 114 | Modified 2009-06-04 21:21:39 | MIT License
play

ActionScript3 source code

/**
 * Copyright yasohachi ( http://wonderfl.net/user/yasohachi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fZHZ
 */

// forked from sake's PV3Dその8 Pixels使ってみる
/*
   久々のPV3D。
   やっぱASは打ってて楽しい。
*/
package
{
	import flash.events.Event;
	import flash.filters.BlurFilter;

	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;

	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="40")]

	public class PV3D_pixels extends BasicView
	{
		private var pixels:Pixels;
		private var rotateX:Number;
		private var rotateY:Number;
                  private var pixelList:Array = [];

		public function PV3D_pixels()
		{
			super(0, 0, true, true);

			var layer:BitmapEffectLayer=new BitmapEffectLayer(viewport, 800, 800, true, 0, BitmapClearMode.CLEAR_PRE, true);
			viewport.containerSprite.addLayer(layer);
			layer.addEffect(new BitmapLayerEffect(new BlurFilter(2, 2, 2), false));

			camera.z=-500;

			rotateX=rotateY=0;

			pixels=new Pixels(layer);
			scene.addChild(pixels);

			for(var i:int=0; i < 500; i++)
			{
				// 赤
				var theta1:Number=360 * Math.random() * Math.PI / 180;
				var theta2:Number=(180 * Math.random() - 90) * Math.PI / 180;
				var radius:Number=200;
				var xx:Number=radius * Math.cos(theta2) * Math.sin(theta1);
				var yy:Number=radius * Math.sin(theta2);
				var zz:Number=radius * Math.cos(theta2) * Math.cos(theta1);
				var p:Pixel3DEX=new Pixel3DEX((0xffff0000), xx, yy, zz);
				pixels.addPixel3D(p);
                                    pixelList.push(p);

				// 黄色
				theta1=360 * Math.random() * Math.PI / 180;
				theta2=(180 * Math.random() - 90) * Math.PI / 180;
				radius=200;
				xx=radius * Math.cos(theta2) * Math.sin(theta1);
				yy=radius * Math.sin(theta2);
				zz=radius * Math.cos(theta2) * Math.cos(theta1);
				p=new Pixel3DEX((0xffffff00), xx, yy, zz);
				pixels.addPixel3D(p);
                                    pixelList.push(p);

				// 白
				theta1=360 * Math.random() * Math.PI / 180;
				theta2=(180 * Math.random() - 90) * Math.PI / 180;
				radius=200;
				xx=radius * Math.cos(theta2) * Math.sin(theta1);
				yy=radius * Math.sin(theta2);
				zz=radius * Math.cos(theta2) * Math.cos(theta1);
				p=new Pixel3DEX((0xffffffff), xx, yy, zz);
				pixels.addPixel3D(p);
                                    pixelList.push(p);

				// オレンジ
				theta1=360 * Math.random() * Math.PI / 180;
				theta2=(180 * Math.random() - 90) * Math.PI / 180;
				radius=200;
				xx=radius * Math.cos(theta2) * Math.sin(theta1);
				yy=radius * Math.sin(theta2);
				zz=radius * Math.cos(theta2) * Math.cos(theta1);
				p=new Pixel3DEX((0xffff8c00), xx, yy, zz);
				pixels.addPixel3D(p);
                                    pixelList.push(p);
			}

			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;
                            */

                            for(var i:int = 0;i < pixelList.length;i++){
                                var p:Pixel3DEX = Pixel3DEX(pixelList[i]);
                                p.move();
                            }

			startRendering();
		}
	}
}

import org.papervision3d.core.geom.renderables.Pixel3D;
import flash.events.Event;
class Pixel3DEX extends Pixel3D{
    private var startX:Number;
    private var startY:Number;
    private var startZ:Number;
    private var rgb:uint;
    private var alpha:Number;
    private var startAlpha:Number;
    private var decrease:Number = 0.99;
    public function Pixel3DEX(color:uint,x:Number=0,y:Number=0,z:Number=0){
        super(color,x,y,z);
        startX = x;
        startY = y;
        startZ = z;
        rgb = 0xffffff & color;
        startAlpha = alpha = (0xff000000 & color) >> 48;
        decrease = Math.random() * 0.09 + 0.9;
    }
    
    public function move():void{
        
        //Pixel3Dってアルファきかないのかしらん?
        if(Math.abs(this.x) < Math.abs(this.startX * 0.1)){
            this.x = startX;
            this.y = startY;
            this.z = startZ;
            this.alpha = startAlpha;
            decrease = Math.random() * 0.09 + 0.9;
        }else{
            this.x *= decrease;
            this.y *= decrease;
            this.z *= decrease;
            alpha *= decrease;
            var a:uint = Math.floor(alpha);
            this.color = uint(alpha) << 48 | color;
        }
    }

}