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

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/37ED
 */

// forked from onedayitwillmake's Lightning
/*
    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;
    import flash.filters.ColorMatrixFilter
    import flash.filters.BlurFilter
    import flash.display.BitmapData
    
    public class FlashTest extends Sprite
    {
        [SWF(frameRate="60")]
        private var _canvas        :BitmapData
        private var _view          :Sprite = new Sprite();
        
        public function FlashTest()
        {
           createBG();
           _canvas = new BitmapData(465,465, true, 0x00000000);
           addChild(new Bitmap(_canvas));
           
           addChild(_view);
           var cx:Number = 10//Math.random() * 465;;
           var cy:Number = Math.random() * -10;
           
            var electricityMouse:ElectricityMouse = new ElectricityMouse(cx, cy)
	    electricityMouse.blendMode = "add";
	    _view.addChild(electricityMouse); 

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


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

          
  
            addEventListener(Event.ENTER_FRAME, draw);
            
        }
private var filter1:BitmapFilter = new ColorMatrixFilter( [ 0.98, 0, -0.2, 0, 0,   0, 0.95, 0, 0, 0,   0, 0, 0.9, 0, 0,   0, 0, 0, 1, 0 ] );
private var filter2:BitmapFilter = new BlurFilter(8,8,1);
private var op:Point = new Point(0,0);

                   
        
        private function draw(e:Event):void
        {
            _canvas.draw(_view);
            _canvas.applyFilter( _canvas, _canvas.rect, op, filter1 );
            _canvas.applyFilter( _canvas, _canvas.rect, op, filter2 );
            _canvas.scroll( Math.random()*8, 16);
        }
        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);
        }
        
        
    } 
}

import flash.display.MovieClip;
import flash.utils.Timer;
import flash.display.Sprite;
import flash.geom.Point;
import flash.filters.BitmapFilter;
import flash.events.TimerEvent


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

           _timer = new Timer(50, 0);
           _timer.addEventListener(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 = (Math.random() < 0.5) ? -10 : 465// _cat.homeX + Math.random() * 465
        _cat.y = _timer.currentCount <= 20 ? 465 : _cat.homeY + Math.random() * 465
    }
    
    private function getPoints(e:flash.events.TimerEvent):void
    {
	moveCat()
	var p:Point;
	var difX:int = stage.mouseX - _cat.x;
	var difY:int = stage.mouseY - _cat.y;
	var choasX:int = 15; 
	var choasY:int = 15;
	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];

		
		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;}
}