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

Lightning

Mario Gonzalez
mario@wddg.com
http://onedayitwillmake.com
/**
 * Copyright onedayitwillmake ( http://wonderfl.net/user/onedayitwillmake )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kbOx
 */

/*
    Mario Gonzalez
    mario@wddg.com
    http://onedayitwillmake.com
*/
package {
    import flash.display.Sprite;
    import flash.display.*;
    import flash.geom.*;
    import flash.events.*
    import flash.utils.Timer;
    import flash.filters.BitmapFilter
    import flash.filters.GlowFilter;
    
    
    public class FlashTest extends Sprite
    {
        [SWF(frameRate="60")]
        public function FlashTest()
        {
           createBG();
           
           var cx:Number = 10//Math.random() * 465;;
           var cy:Number = Math.random() * -10;
           
            var electricityMouse:ElectricityMouse = new ElectricityMouse(cx, cy)
	    electricityMouse.blendMode = "add";
	    addChild(electricityMouse); 

            electricityMouse = new ElectricityMouse(cx,cy)
	    electricityMouse.blendMode = "add";
	    addChild(electricityMouse);


            cx = 450// Math.random() * 465;
            electricityMouse = new ElectricityMouse(cx, cy)
	    electricityMouse.blendMode = "add";
	    addChild(electricityMouse);

            electricityMouse = new ElectricityMouse(cx,cy)
	    electricityMouse.blendMode = "add";
	    addChild(electricityMouse);
        }
         
        private function createBG():void 
        {
             // write as3 code here..
            var matr:Matrix = new Matrix();
                matr.createGradientBox(465, 465, Math.PI / 2, 0, 0);
            var bg:Sprite = new Sprite();
            bg.graphics.beginGradientFill
            (
                GradientType.LINEAR, 
                [0x001E33, 0x364D89, 0x001E33], //colors
                [1, 1, 1], //alphas
                [0, 255, 255], //ratios
                matr, //matrix
                SpreadMethod.PAD
            );
            bg.graphics.drawRect( 0, 0, 465, 465);
            
            addChild(bg);
        }
        
        
    } 
}

class ElectricityMouse extends flash.display.Sprite
{
    public  var _cat			:flash.display.MovieClip;
    private var _points	                :Array = new Array();
    private var _noisePoints       	:Array = new Array();
    
    private var _numPoints		:int = 30;
    private var _timer			:flash.utils.Timer;	
    private var _glowSprite		:flash.display.Sprite;
    
    function ElectricityMouse(cx:Number, cy:Number):void
    {
            _cat = new flash.display.MovieClip();
            _cat.x = _cat.homeX = cx//
            _cat.y = _cat.homeY = cy//Math.random() * -20;
            
           _glowSprite = new flash.display.Sprite();
           
           for (var i:int = 0; i <= _numPoints; i++)
        	_points[i] = new flash.geom.Point();
        
           var filter:flash.filters.BitmapFilter = getBitmapFilter();
           filters = [filter];
           
           _glowSprite.blendMode = "overlay";
//            _glowSprite.alpha = 0;

           _timer = new flash.utils.Timer(50, 0);
           _timer.addEventListener(flash.events.TimerEvent.TIMER, getPoints);
           _timer.start();
    }
    private function moveCat():void
    {
        //Check if this is the first ten firings
        //That way we can force it to go to the bottom center
        //For a prettier screenshot 
        _cat.x = _timer.currentCount <= 20 ? 232 : _cat.homeX + Math.random() * 250 - 125;
        _cat.y = _timer.currentCount <= 20 ? 465 : _cat.homeY + Math.random() * 90 - 45;
    }
    
    private function getPoints(e:flash.events.TimerEvent):void
    {
	moveCat()
	var p:flash.geom.Point;
	var difX:int = stage.mouseX - _cat.x;
	var difY:int = stage.mouseY - _cat.y;
	var choasX:int = 30; 
	var choasY:int = 30;
	var maxStroke:int = 5;
	var segmentColor:uint;
	var colors:Array = new Array(0x00E4F0, 0x2899FF, 0x94e0f4, 0x66d7f5);
	
	graphics.clear();
	_glowSprite.graphics.clear();
	
	//Get the path
	for (var i:int = 0; i <= _numPoints; i++)
	{
		p = _points[i];
		//trace((i, cat.x, stage.mouseX, _numPoints) - cat.x)
		
		p.x = easeNone(i, _cat.x, difX, _numPoints)
		p.y = easeNone(i, _cat.y, difY, _numPoints)
	}
	
	//Add noise
	for (i = 0; i <= _numPoints; i++)
	{
		p = _points[i];
		p.x += Math.random() * choasX;
		p.y += Math.random() * choasY;
	}
	
	//Draw the path
	graphics.moveTo(_cat.x, _cat.y);
	_glowSprite.graphics.moveTo(_cat.x, _cat.y);
	for (i = 0; i <= _numPoints; i++)
	{
		segmentColor = colors[Math.floor(Math.random() * colors.length)]
		
		graphics.lineStyle(Math.random() * maxStroke, segmentColor, Math.random() * 0.25 + 0.75);
		_glowSprite.graphics.lineStyle(0.25, 0xffffff, 0.5);
		
		graphics.lineTo(_points[i].x, _points[i].y);
		_glowSprite.graphics.lineTo(_points[i].x, _points[i].y);
	}
    }

    private function getBitmapFilter():flash.filters.BitmapFilter {
			var color:Number = 0x66FFFF;
			var alpha:Number = 1;
			var blurX:Number = 16;
			var blurY:Number = 16;
			var strength:Number = 3;
			var inner:Boolean = false;
			var knockout:Boolean = false;
			var quality:Number = 3;


			return new flash.filters.GlowFilter(color,
								  alpha,
							 	  blurX,
								  blurY,
								  strength,
								  quality,
								  inner,
								  knockout);
		}

public function easeNone (t:Number, b:Number, c:Number, d:Number):Number {return c*t/d + b;}
}