import flash.geom.Point import flash.events.Event import flash.display.Bitmap import flash.display.BitmapData import flash.filters.BitmapFilter import flash.filters.DisplacementMapFilter import flash.filters.DisplacementMapFilterMode // Setup our perlin noise map BitmapData and noise seed var bmd:BitmapData = new BitmapData(250,250); var seed:Number = Math.floor(Math.random()*int.MAX_VALUE); var speed:Number = .5; var t:Number = 0; // Add the noise map to the stage var map:Bitmap = Bitmap(addChild(new Bitmap(bmd))); map.x = map.width; // WaterfallPic is an image with library linkage class 'WaterfallPic' var image:Bitmap = Bitmap(addChild(new Bitmap(new WaterfallPic(0,0)))); // Set the enterFrame event to call the 'update' function addEventListener(Event.ENTER_FRAME,update); // Redraws the noise map and main image function update (e:Event):void { // The value 't' governs positions of the offset mapping points t += speed; // Create an array of points that offset our 4 noise map octaves var pointsArray:Array = [new Point(-t,t/2),new Point(t/2,-t),new Point(t,t),new Point(t,0),new Point(0,-t)]; // Create perlin noise with the same seed, but the new offsets bmd.perlinNoise(100, 100, 4, seed, true, false, 1, true, pointsArray); // Apply this as a DisplacementMapFilter for our waterfall image image.filters = [getBitmapFilter(bmd)]; } // Returns a DisplacementMapFilter from the given BitmapData function getBitmapFilter(mapBitmap:BitmapData):BitmapFilter { return new DisplacementMapFilter(mapBitmap, new Point(0,0), 1, 1, 25, 25, "wrap", 0, 0); }