forked from: lightning
/**
* Copyright Chow.Ka.Ho ( http://wonderfl.net/user/Chow.Ka.Ho )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/b1dC
*/
// 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 = "0xFFFFFF", 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(0x333333, 1, 15, 15, 8, 2)]
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 xx:Number = Math.random()*465;
var yy:Number = 0;
var th:Number = random(2) +1
tg.graphics.clear();
tg.graphics.moveTo(xx, yy);
while(yy < stage.stageHeight){
xx += random(20) * (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);
}
}
}