package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Point; [SWF(width="500",height="400")] public class SmokeFog extends Sprite { private var vectormap:BitmapData; private var bmpdata:BitmapData; private var oy:int = 0; private var w:int; public function SmokeFog(){ w = 200; vectormap = new BitmapData(w, w); bmpdata = new BitmapData(w, w, false, 0); addChild(new Bitmap(bmpdata)); stage.addEventListener(Event.ENTER_FRAME, reset); } private function reset(e:Event):void { vectormap.perlinNoise(w * .5, w * .5, 3, 1, false, true, 7, false, [new Point(0, oy++)]); bmpdata.fillRect(bmpdata.rect, 0); for (var y:int = 0; y < vectormap.height; y++){ for (var x:int = 0; x < vectormap.width; x++){ var px:uint = vectormap.getPixel(x, y); var r:int = px >> 16 & 0xFF; var g:int = px >> 8 & 0xFF; var b:int = px & 0xFF; var tx:int = x + (g / 0xFF - .5) * w; var ty:int = y + (b / 0xFF - .5) * w; if (ty < 0 || ty >= bmpdata.height || tx < 0 || tx >= bmpdata.width) continue; var col:uint = bmpdata.getPixel(tx, ty); col += 0x010101 * (int)(r * .2); if (col > 0xFFFFFF) col = 0xFFFFFF; bmpdata.setPixel(tx, ty, col); } } } }}