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

forked from: lightning

Get Adobe Flash player
by kazuyuki 06 Apr 2010
/**
 * Copyright kazuyuki ( http://wonderfl.net/user/kazuyuki )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/heRz
 */

// forked from kiyobu's lightning
package {
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.events.Event;
    import flash.filters.GlowFilter;
    import flash.filters.BlurFilter;
    import flash.display.BlendMode;
    import flash.geom.ColorTransform;
    [SWF(width = "465", height = "465", backgroundColor = "0x000000", frameRate = "30")]
    public class FlashTest extends Sprite {
    		public var layer:Array = new Array();
        public function FlashTest() {
	        	layer[0] = new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000));
	        layer[0].filters = [new BlurFilter(2,2,1)]
			layer[1] = new Sprite();
			layer[1].filters = [new BlurFilter(2,2,1), new GlowFilter(0x4411ff, 1, 32, 32, 8, 3)]
			addChild(layer[0]);
			addChild(layer[1]);
        		addEventListener(Event.ENTER_FRAME, loop);
        }
        public function loop(e:Event):void{
        		lightning(layer[1]);
        		var cash:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000);
        		cash.draw(this, null, new ColorTransform(1,1,1,0.9), BlendMode.ADD);
   			layer[0].bitmapData = cash;
        }
        public function lightning(tg:Sprite):void{
        		var xx:Number = mouseX;
        		var yy:Number = mouseY;
        		var th:Number = random(2) +1
        		tg.graphics.clear();
        		tg.graphics.moveTo(xx, yy);
        		while(yy < stage.stageHeight){
        			xx += random(50) * (random(2)*2 -1);
        			yy += random(30) + 4	;
        			tg.graphics.lineStyle(th,0xffffff,1);
        			tg.graphics.lineTo(xx,yy);
        		}
        }
        public function random(n:Number):Number{
        		return Math.floor(Math.random() * n);
        }
    }
}