Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.geom.Rectangle;
- import net.flashpunk.Entity;
- import net.flashpunk.FP;
- import flash.geom.Point;
- import flash.filters.DisplacementMapFilter;
- import flash.filters.DropShadowFilter;
- import net.flashpunk.graphics.Canvas;
- import net.flashpunk.utils.Draw;
- import flash.display.BlendMode;
- /**
- * ...
- * @author Todd Luke
- */
- public class Water extends Entity
- {
- // Perlin noise variables, I encourage you to play around with these...
- public var baseX :Number = 32;
- public var baseY :Number = 32;
- public var nOctaves :Number = 1;
- public var randomSeed :Number = Math.random()*10;
- public var bStitch :Boolean = true;
- public var bFractalNoise :Boolean = true;
- public var nChannels :Number = 1;
- public var bGreyScale :Boolean= false;
- // Offset array for perlin function
- public var p1:Point = new Point(450, 340);
- public var p2:Point = new Point(500, 600);
- public var perlinOffset:Array = new Array(p1, p2);
- // Create the bitmapdata we are going to change with the perinNoise function
- public var bmp:BitmapData = new BitmapData(320,240,true,0x00000000);
- private var caRoom:Canvas = new Canvas( FP.width, FP.height);
- public var _rect:Rectangle = new Rectangle(0, 0, FP.width, FP.height);
- public function Water()
- {
- trace("water created");
- layer = -2;
- }
- override public function render():void
- {
- super.render();
- // change the values in the perlinOffset to animate each perlin layer
- bmp.copyPixels(FP.buffer, _rect, _rect.topLeft);
- perlinOffset[0].y-=1;
- perlinOffset[0].x-=1;
- perlinOffset[1].x+=1;
- perlinOffset[1].y+=1;
- // apply perlin noise to our bitmapdata
- bmp.perlinNoise(baseX, baseY, nOctaves, randomSeed, bStitch, bFractalNoise, nChannels, bGreyScale, perlinOffset);
- //
- // Uncomment the following line to see the generated perlin noise
- //_root.attachBitmap(bmp, 1, "auto", true);
- //
- // Now use the bitmapdata in bmp as a base for the distortion
- var dmf:DisplacementMapFilter = new DisplacementMapFilter(bmp, new Point(0, 0), 1, 1, 20, 20, "color");
- // and apply it to our pic (instance name sourcePic)
- bmp.applyFilter(FP.buffer, _rect, _rect.topLeft, dmf);
- caRoom.fillTexture(_rect, bmp); //render the blurred background to the canvas.
- caRoom.blend = BlendMode.HARDLIGHT;
- caRoom.alpha=.3
- Draw.graphic(caRoom, FP.camera.x, FP.camera.y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment