flash on 2009-11-26

by fishKing
♥0 | Line 107 | Modified 2009-11-26 20:11:02 | MIT License
play

ActionScript3 source code

/**
 * Copyright fishKing ( http://wonderfl.net/user/fishKing )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/39Oh
 */

package 
{
	import flash.utils.getTimer;
	import flash.geom.*;
	import flash.display.*;

	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BlurFilter;
	import flash.net.*;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.system.LoaderContext;

	import flash.text.*;


	[SWF(backgroundColor="0x000000", width = "456" , height = "456" , frameRate="30")]
	public class Winter extends Sprite
	{

            
		public static const _sw:uint = 456;
	        public static const _sh:uint = 456;
		public static const _isw:Number = 1 / _sw;
		public static const _ish:Number = 1 / _sh;

		public var sw:uint = _sw;
		public var sh:uint = _sh;


		private var offSetX:int = 0;
		private var offSetY:int = 0;

		public var isSound:Boolean = false;

		public var display:Bitmap;
		public var _background:Bitmap;
		public var blur:BlurFilter;
		public var myMask:Sprite = new Sprite();
		private const IMAGE_URL:String = "http://www.chutaicho.com/image/leafs.jpg";

		var matrix:Matrix = new Matrix();
            private static const linear:String = GradientType.RADIAL;
            private static const colors:Array = [0xFFFFFF,0xFFFFFF];
            private static const alphas:Array = [1.0,0.0];
            private static const ratios:Array = [0.0,255];
            private static const spread:String = SpreadMethod.PAD;
		var gradient:Shape = new Shape();
		var gradientBitmap:BitmapData;
		var result:BitmapData;
		var whitePlate:Bitmap = new Bitmap(new BitmapData(1024,768,true,0x0FFFFFFF));

		public function Winter ():void
		{
			if (stage)
			{
				init ();
			}
			else
			{
				addEventListener (Event.ADDED_TO_STAGE,init);
			}
		}
		private function init (e:Event=null):void
		{
			removeEventListener (Event.ADDED_TO_STAGE,init);
			addEventListener (Event.ENTER_FRAME,render);
			stage.addEventListener (MouseEvent.MOUSE_MOVE,_onMouseMove);
			addEventListener (MouseEvent.MOUSE_MOVE,_onMouseMove);
			stage.addEventListener (MouseEvent.CLICK,restart);
			addEventListener (MouseEvent.CLICK,restart);
			
			var req:URLRequest = new URLRequest(IMAGE_URL);
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);    
			loader.load( req, new LoaderContext(true));
 
		}
		public function loadComplete (e:Event = null):void
		{

			e.target.removeEventListener (Event.COMPLETE,loadComplete);
			_background = e.target.content;
			display = new Bitmap(new BitmapData(_background.width,_background.height,true,0x000000));
			display.bitmapData.draw (_background);
			gradientBitmap = new BitmapData(display.width,display.height,true,0);

			result = new BitmapData(display.width,display.height,true,0);
			addChild ( new Bitmap( result ) );
		}
		private function restart (e:MouseEvent):void
		{
		}
		var pastMouse:Point = new Point(0,0);

		private function _onMouseMove (e:MouseEvent):void
		{
			var d:Number = Point.distance(pastMouse,new Point(mouseX,mouseY));
			if (display)
			{
				var gradientSize:Number = Math.random() * 50+d*10;
				var _tx:Number = mouseX - gradientSize / 2;
				var _ty:Number = mouseY - gradientSize / 2;

				matrix.createGradientBox ( gradientSize , gradientSize, Math.PI  ,_tx,_ty );

				gradient.graphics.clear ();
				gradient.graphics.beginGradientFill ( linear, colors, alphas, ratios, matrix, spread );
				gradient.graphics.drawCircle (mouseX,mouseY, gradientSize);
				gradient.graphics.endFill ();
				gradientBitmap = new BitmapData(display.width,display.height,true,0);
				gradientBitmap.draw ( gradient );
				result.draw (whitePlate);
				result.copyPixels ( display.bitmapData, result.rect, new Point(), gradientBitmap, new Point(), true );


			}
			pastMouse.x = mouseX;
			pastMouse.y = mouseY;

		}
		private function render (e:Event):void
		{
			if (_background)
			{
			}
		}
	}

}

Forked