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: パーティクルシステム

色々頑張って軽くしてみた

「初めてのActionScript3.0」(O'REILLY)の7章モーションにパーティクルシステムがあり、	 
これが2Dで実現されていたので、これをpapervision3dを使用し3Dに変えてみました。
Get Adobe Flash player
by uwi 04 Oct 2009
/**
 * Copyright uwi ( http://wonderfl.net/user/uwi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/qdKT
 */

// forked from hankuro's パーティクルシステム
package {
    	import flash.display.Sprite;
    	import flash.events.*;
    	import net.hires.debug.Stats;
    	[SWF(width = 540, height = 400, backgroundColor = 0x000000)]
    	// 色々頑張って軽くしてみた
    	/*
    	 * 「初めてのActionScript3.0」(O'REILLY)の7章モーションにパーティクルシステムがあり、	 
    	 * これが2Dで実現されていたので、これをpapervision3dを使用し3Dに変えてみました。 	 
    	 */
    	 	public class Main extends Sprite{
    	 	    public function Main() {
    	 	        addChild(new ParticleView());
//    	 	        addChild(new Stats());
    	 	    }
    	 	}
}
		import flash.events.Event;
		import org.papervision3d.core.effects.view.ReflectionView;
		import org.papervision3d.objects.primitives.Sphere;
		import org.papervision3d.lights.PointLight3D;
		import org.papervision3d.materials.shadematerials.GouraudMaterial;
		class ParticleView extends ReflectionView{
		    private var _balls : Array;
		    private var pointLight:PointLight3D;
		    
		    public function ParticleView()
		    {
		        super(540,400,false, false);
		        _balls = [];
		        surfaceHeight = -50;
		        camera.z = -400;
		        pointLight = new PointLight3D();
		        pointLight.x = -200;
		        pointLight.y = 200;
		        pointLight.z = -90;
		        scene.addChild(pointLight);
		        addEventListener(Event.ENTER_FRAME,onRun , false, 0, true);
		    }
		    private var _ct : int = 0;
		    
		    private function appendBall() : void
		    {
		        if(_ct == 2){
		        var ball : Object = {
		            xpos : 0,
		            ypos : 200,
		            xvel : (Math.random() > 0.5 ? 1 : -1) * (Math.random() * 5 + 2.0), // 早くはけるように
		            yvel : Math.random() * -20,
		            grav : 0.1,
		            bounce : -0.7,
		            sphere : new Sphere(new GouraudMaterial(pointLight, Math.random() * 0xffffff, 0x000000), Math.random() * 15 + 10, 6, 6)
		        };
		        ball.sphere.x = ball.xpos;
		        ball.sphere.y = ball.ypos;
		        ball.sphere.alpha = .08;
		        _balls.push(ball);
		        
		        scene.addChild(ball.sphere);
		        _ct = 0;
		    }
		    _ct++;
		    }
		    
		    private function moveBall() : void
		    {
		        for(var i : int = _balls.length - 1;i >= 0;i--){
		            var b : Object = _balls[i];
		            b.xpos += b.xvel;
		            b.ypos += b.yvel;
		            b.yvel -= b.grav;
    		        b.sphere.x = b.xpos;
		            b.sphere.y = b.ypos;
		            b.sphere.z = b.xpos;
		            
    		        if ( b.sphere.z < -200 ||  b.sphere.z > 300) {
    		            scene.removeChild(b.sphere);
    		            if(i != _balls.length - 1){
    		                _balls[i] = _balls.pop();
    		            }else{
    		                _balls.pop();
    		            }
  		                continue;
    		        }
    		        if (b.ypos < 0 && b.yvel < 0) {
		                b.ypos = 0;
		                b.yvel *= b.bounce;
		            }
		        }
		    }
		    
		    private function onRun(evt:Event):void {
		        appendBall();
		        
		        moveBall();
		        
		        singleRender();
		    }
		 }