Simple Perlin Noise Fire 2009-10-5

by PESakaTFM
♥0 | Line 43 | Modified 2010-12-03 00:46:56 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Graphics;
    import flash.filters.DisplacementMapFilter;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.events.Event;
    
    public class FlashTest extends Sprite {
       public var bmp:Bitmap;    
       public var bmd:BitmapData;
       public var seed:Number;
       public var offset:Array;        
       public function FlashTest()    
       {        
           var g:BitmapData = new BitmapData(60,200,false,0);        
           g.fillRect(new Rectangle(10,25,40,150),0xFF0000);        
           bmp = new Bitmap(g);        
           bmp.x = 10;        
           bmp.y = 10;        
           this.addChild(bmp);                
           bmd = new BitmapData(300,300);        
           offset = [new Point(0,0),new Point(0,0),new Point(0,0)];        
           seed = Math.floor(Math.random()*1000);        
           bmd.perlinNoise(15,  15,  3,  seed,  false, false,  5,  false, offset);    
   //        this.addChild(new Bitmap(bmd));    
           this.cacheAsBitmap = true;                
           this.filters = [new DisplacementMapFilter(bmd,new Point(0,0),1,4,15,-30)];                
           this.addEventListener(Event.ENTER_FRAME, onEnter);    
        }    
        private function onEnter(e:Event):void    
        {        
            offset[0].x += 1;        
            offset[0].y += 2;        
            offset[1].x += -1;        
            offset[1].y += -1;        
            offset[2].x += 2;        
            offset[2].y += 1;        
            bmd.perlinNoise(15,  15,  3,  seed,  false, false,  5,  false, offset);        
            this.filters = [new DisplacementMapFilter(bmd,new Point(0,0),1,4,15,-30)];    
         }
    }
}

Forked