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

擬似ボリュームパーティクル

高速化とかメモリがどうとかは一切なされてません。
パーティクルにライティングっぽい処理を施して立体的に見せてます
/**
 * Copyright kuma360 ( http://wonderfl.net/user/kuma360 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/u4Op
 */

//高速化とかメモリがどうとかは一切なされてません。
//パーティクルにライティングっぽい処理を施して立体的に見せてます
package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.filters.DisplacementMapFilter;
    import flash.geom.Matrix;
    import net.hires.debug.Stats;
    
    public class Main extends Sprite 
    {
        public function Main():void 
        {
            /////////////////////
            var CANVAS:BitmapData = new BitmapData ( 465 , 465 , false , 0 ) ;
            addChild ( new Bitmap ( CANVAS ) ) ;
            
            addChild ( new Stats ) ;
            
            /////////////////////
            //汎用
            var S:Sprite = new Sprite ;
            var G:Graphics = S.graphics ;
            
            
            /////////////////////
            //ライティング用
            var M1:Matrix = new Matrix ;
            M1.createGradientBox ( 200 , 200 , - 45 * ( Math.PI/ 180) ) ;
            G.beginGradientFill( "radial" , [ 0xFFFFFF , 0 ] , [ 1 , 0 ] , [ 0 , 255 ] , M1 , "pad" , "pad" , 0.7 ) ;
            G.drawRect ( 0 , 0  , 200 , 200 ) ;
            G.endFill ( ) ;
            
            var B:BitmapData = new BitmapData ( 465 , 465 , false , 0 ) ;
            B.draw ( S ) ;
            
            
            /////////////////////
            //煙生成
            G.beginGradientFill( "radial" , [ 0x909090 , 0x000000 ] , [ 0 , 1 ] , [ 120 , 255 ] ) ;
            G.drawRect ( -200 , -200 , 400 , 400 ) ;
            G.endFill ( ) ;
            
            var A:BitmapData = new BitmapData( 400 , 400 , true , 0 ) ;
            A.perlinNoise ( 60 , 60 , 14 , Math.random() * 999 , true , true , 7 , true ) ;
            S.filters = [ new DisplacementMapFilter ( A , null , 1 , 2 , 50 , 50 , "wrap" , 0 , 1 ) ];
            
            var M2:Matrix = new Matrix ;
            M2.identity ( ) ;
            M2.translate ( 200 , 200 ) ;
            A.draw ( S , M2 ) ;
            
            
            /////////////////////
            //回転分の用意
            var V:Vector.<BitmapData> = new Vector.<BitmapData> ( ) ;
            {
                
                var M3:Matrix = new Matrix ;
                
                for ( var I:int = 0 ; I < 360 ; ++ I ) {
                    
                    M3.identity ( ) ;
                    M3.translate ( - 200 , - 200 ) ;
                    M3.rotate ( I * ( Math.PI / 180 ) ) ;
                    M3.translate ( 200 , 200 ) ;
                    M3.scale ( 0.5 , 0.5 ) ;
                    
                    var TEMP1:BitmapData = new BitmapData ( 200 , 200 , true , 0 ) ;
                    TEMP1.draw ( A , M3 ) ;
                    TEMP1.draw ( B , null , null , BlendMode.OVERLAY ) ;
                    TEMP1.draw ( B , null , null , BlendMode.OVERLAY ) ;
                    TEMP1.draw ( B , null , null , BlendMode.OVERLAY ) ;
                    
                    V.push ( TEMP1 ) ;
                    
                }
                
            }
            
            
            /////////////////////
            //クリックで表示
            var P:Vector.<Particle> = new Vector.<Particle> ( ) ;
            stage.addEventListener (
                MouseEvent.CLICK ,
                function ( ) :void {
                }
            ) ;
            
            
            /////////////////////
            //RUN
            var K:Number = 0 ;
            addEventListener (
                Event.ENTER_FRAME ,
                function ( ) :void {
                    
                    for ( var L:int = 0 ; L < 3 ; ++ L ) {
                        P.push ( new Particle ( mouseX , mouseY ) ) ;
                    }
                    CANVAS.fillRect ( CANVAS.rect , 0x1893C0 ) ;
                    
                    for ( var I:int = 0 ; I < P.length ; ++ I ) {
                        P[I].update ( ) ;
                    }
                    
                    for ( var J:int = 0 ; J < P.length ; ++ J ) {
                        P[J].render ( CANVAS , V ) ;
                    }
                    
                    for ( var K:int = 0 ; K < P.length ; ++ K ) {
                        if ( P[K].TIME < 0 ) {
                            P.splice ( K , 1 ) ;
                        }
                    }
                    
                }
            ) ;
            
            
        }
        
    }
    
}


import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.geom.ColorTransform;
import flash.geom.Matrix;

class Particle {
    
    private var _X:Number;
    private var _Y:Number;
    private var _VX:Number;
    private var _VY:Number;
    
    private var _R:Number;
    private var _RR:Number;
    private var _M:Matrix;
    
    private var _TIME:int ;
    public function get TIME ( ) :int {
        return _TIME ;
    }
    
    public function Particle ( x:Number , y:Number ) {
        
        _M = new Matrix ;
        
        _X = x - 100 + Math.random() * 50 - 25 ;
        _Y = y - 100 + Math.random() * 50 - 25 ;
        _VX = ( Math.random ( ) * 5 - 2 ) ;
        _VY = ( Math.random ( ) * 5 - 2 ) ;
        
        _R = Math.random ( ) * 360 ;
        _RR = Math.random ( ) * 11 - 5 ;
        _TIME = 50 ;
        
    }
    
    public function update ( ) :void {
        _X += _VX ;
        _Y += _VY ;
        -- _TIME ;
    }
    
    public function render ( canvas:BitmapData , v:Vector.<BitmapData> ) :void {
        
        _M.identity ( ) ;
        _M.translate ( _X , _Y ) ;
        
        _R += _RR ;
        _R += 360 ;
        _R %= 360 ;
        
        canvas.draw ( v[ Math.floor ( _R ) ] , _M , new ColorTransform ( 1,1,1, _TIME/50 ) , BlendMode.SCREEN ) ;
        
    }
    
}