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: forked from: ビリビリ(Lightning Effect)

比較的簡単に実装できそうな方法で
稲妻というか放電風のビリビリを作ってみました。

マウスクリックでビリビリの出現点が変化します。
/**
 * Copyright voidbox ( http://wonderfl.net/user/voidbox )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hbXQ
 */

// forked from voidbox's forked from: ビリビリ(Lightning Effect)
// forked from mousepancyo's ビリビリ(Lightning Effect)
/*
比較的簡単に実装できそうな方法で
稲妻というか放電風のビリビリを作ってみました。

マウスクリックでビリビリの出現点が変化します。
*/

package {    
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.events.Event;
    import flash.geom.Point;
    import flash.display.Sprite;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.filters.GlowFilter;
    import flash.events.MouseEvent;
    
    [SWF(width="465", height="465", backgroundColor="0", frameRate="30")]
    
    public class Main extends Sprite{
        private const W:Number = 465;
        private const H:Number = 465;
        private const RANGE:int = 5;
        private var _p:Point;
        private var _sp:Sprite;
        private var _ctf:ColorTransform;
        private var _canvas:BitmapData;
        private var _glow:BitmapData;
        private var _lights:Vector.<Light> = new Vector.<Light>();

        public function Main() {
            init();
            addEventListener(Event.ENTER_FRAME, update)    ;
            stage.addEventListener(MouseEvent.CLICK, onDown);
        }
        
        private function init():void{
            _p = new Point( W/2, H/2 );
            _sp = new Sprite();
            _sp.filters = [new GlowFilter(0xC9E6FC, 1, 10, 10, 4, 3, false, false)];
            _ctf = new ColorTransform(0.9, 0.96, 1, 0.9);
            _canvas = new BitmapData(W,H,false,0);
            
            var bm:Bitmap = new Bitmap(_canvas, "auto", true);
            _glow = new BitmapData(W / RANGE, H / RANGE, false, 0);
            
            var glowBm:Bitmap = new Bitmap(_glow, "never", true);
            glowBm.blendMode = "add";
            glowBm.scaleX = glowBm.scaleY = RANGE;
            
            addChild(bm);
            addChild(glowBm);
        }
        
        private function onDown(e:MouseEvent):void{
            _p = new Point(mouseX, mouseY);
        }
                
        private function update(e:Event):void{
        
            _sp.graphics.clear();

            var light_count:int = Math.random() * 15;
            for( var i:int = 0; i<light_count; ++i ) {
            
                add_light();
            }
            
            update_lights();

            _canvas.colorTransform(_canvas.rect, _ctf);
            _canvas.draw(_sp);
            _glow.draw(_canvas, new Matrix(1 / RANGE, 0, 0, 1 / RANGE));
        }

        private function add_light():void{
            
            var light:Light = new Light();
            var angle:Number = Math.random() * Math.PI * 2.0;
            var dir:Point = new Point( Math.sin(angle),Math.cos(angle) );
            light.pos.x = _p.x;
            light.pos.y = _p.y;
            light.dir.x = dir.x;
            light.dir.y = dir.y;
            _lights.push(light);
        }

        private function update_lights():void{
            
            var num:int = Math.random() * 3;
            _sp.graphics.lineStyle(num, 0xFFFFFF, 1-(num/10));
            
            for( var i:int = 0; i<_lights.length; ) {
                
                var xxx:int = Math.random() * 8 + 2;                
                var light:Light = _lights[i];
                _sp.graphics.moveTo( light.pos.x, light.pos.y );

                for( var j:int = 0; j<xxx; ++j ) {
            
                    var n:int = Math.random() * 10 + 5;
                    var d:Number = n * ( Math.random() - 0.5 ) * 2.0;
                    light.pos.y += light.dir.y * n + light.dir.x * d;
                    light.pos.x += light.dir.x * n - light.dir.y * d;
                    _sp.graphics.lineTo( light.pos.x, light.pos.y );
                }
                
                if( 0.0 < light.pos.x && light.pos.x < W &&
                    0.0 < light.pos.y && light.pos.y < H ) {                        

                    ++i;
                }
                else {
               
                    _lights.splice( i, 1 );
                }

            }
        }
    }
}

import flash.geom.Point;
class Light {

    public var pos:Point = new Point();
    public var dir:Point = new Point();
}