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

キラキラ星と空間 (2)

//////////////////////////////////////////////////////////////////////////////
キラキラ星と空間 (2)	[Papervision3D]
//////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by ProjectNya 18 May 2010
    Embed
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fqSj
 */

////////////////////////////////////////////////////////////////////////////////
// キラキラ星と空間 (2)	[Papervision3D]
////////////////////////////////////////////////////////////////////////////////

package {

	import flash.display.Sprite;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import flash.display.PixelSnapping;
	import flash.display.BlendMode;
	import flash.geom.Matrix;
	import flash.filters.BlurFilter;
 	import flash.events.Event;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.core.geom.Pixels;
	import org.papervision3d.core.geom.renderables.Pixel3D;
	import org.papervision3d.view.layer.BitmapEffectLayer;
	import org.papervision3d.core.effects.BitmapLayerEffect;

	[SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]

	public class Main extends Sprite {
		private var scene:Scene3D;
		private var camera:Camera3D;
		private var viewport:Viewport3D;
		private var overlay:Scene3D;
		private var overlayport:Viewport3D;
		private var renderer:BasicRenderEngine;
		private var pixels:Pixels;
		private var effect:BitmapEffectLayer;
		private var bitmapData:BitmapData;
		private static var scale:uint = 4;
		private var matrix:Matrix;
		private static var colors:Array = [0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFF00, 0xFF00FFFF];
		private var angle:Number = 90;
		private static var radius:uint = 1000;

		public function Main() {
			//Wonderfl.capture_delay(8);
			init();
		}

		private function init():void {
			graphics.beginFill(0x000000);
			graphics.drawRect(0, 0, 465, 465);
			graphics.endFill();
			scene = new Scene3D();
			overlay = new Scene3D();
			camera =new Camera3D();
			camera.z = -1000;
			camera.focus = 500;
			camera.zoom = 1;
			camera.target = DisplayObject3D.ZERO;
			viewport = new Viewport3D(0, 0, true, false);
			overlayport = new Viewport3D(0, 0, true, false);
			addChild(viewport);
			renderer = new BasicRenderEngine();
			addEventListener(Event.ENTER_FRAME, render, false, 0, true);
			effect = new BitmapEffectLayer(viewport, 465, 465);
			viewport.containerSprite.addLayer(effect);
			effect.addEffect(new BitmapLayerEffect(new BlurFilter(4, 4, 3), false));
			pixels = new Pixels(effect);
			scene.addChild(pixels);
			for (var n:uint = 0; n < 1600; n++) {
				var px:Number = Math.random()*2000 - 1000;
				var py:Number = Math.random()*2000 - 1000;
				var pz:Number = Math.random()*2000 - 1000;
				var id:uint = Math.floor(Math.random()*colors.length);
				var pixel:Pixel3D = new Pixel3D(colors[id], px, py, pz);
				pixels.addPixel3D(pixel);
			}
			bitmapData = new BitmapData(465/scale, 465/scale, false, 0xFF000000);
			var bitmap:Bitmap = new Bitmap(bitmapData, PixelSnapping.NEVER, true);
			bitmap.scaleX = bitmap.scaleY = scale;
			bitmap.blendMode = BlendMode.ADD;
			addChild(bitmap);
			addChild(overlayport);
			matrix = new Matrix(1/scale, 0, 0, 1/scale, 0, 0);
		}
		private function render(evt:Event):void {
			bitmapData.lock();
			bitmapData.fillRect(bitmapData.rect, 0xFF000000);
			bitmapData.draw(viewport, matrix);
			bitmapData.unlock();
			angle ++;
			var cp:Number = Math.sin(angle*Math.PI/180)*radius*0.4+ radius*0.6;
			camera.x = cp*Math.sin(angle*Math.PI/180);
			camera.y = cp*Math.sin(angle*Math.PI/180);
			camera.z = cp*Math.cos(angle*Math.PI/180);
			renderer.renderScene(scene, camera, viewport);
			renderer.renderScene(overlay, camera, overlayport);
		}
		
	}

}