MikanGlid
/**
* Copyright yd_niku ( http://wonderfl.net/user/yd_niku )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/q3J6
*/
// forked from yd_niku's forked from: flash on 2009-11-18
// forked from yd_niku's flash on 2009-11-18
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.geom.*;
import jp.progression.commands.*;
import jp.progression.commands.display.*;
import jp.progression.commands.net.*;
import jp.progression.commands.lists.*;
import com.flashdynamix.utils.SWFProfiler;
public class FlashTest extends Sprite {
public var source:BitmapData;
public var canvas:Sprite = new Sprite();
public var matrix:Matrix = new Matrix();
public function FlashTest() {
if( stage ) setup();
else addEventListener( Event.ADDED_TO_STAGE, setup );
}
public function setup(e:Event=null):void{
removeEventListener( Event.ADDED_TO_STAGE, setup );
SWFProfiler.init( this );
stage.addEventListener( Event.RESIZE, resizeHandler );
resizeHandler();
canvas.x = cx;
canvas.y = cy;
addChild( canvas );
var loader:MikanLoader = new MikanLoader();
new SerialList( null,
new Func( loader.load, null, loader, Event.COMPLETE ),
function():void {
var data:BitmapData = loader.data as BitmapData;
source = new BitmapData( data.width+2, data.height+2, true, 0 );
source.draw( data, new Matrix(1,0,0,1,1,1) );
},
startBitmapFill
).execute();
}
public function startBitmapFill():void {
addEventListener( Event.ENTER_FRAME, update );
}
public function update(e:Event):void {
calcuration();
fill();
}
private function calcuration():void{
var dx:Number = cx - mouseX;
var dy:Number = cy - mouseY;
var sq:Number = dx*dx + dy*dy;
var stageSq:Number = sw*sw+ sh*sh;
targetScale = sq/stageSq*30;
targetRotation = Math.atan2( dy, dx );
targetX = mouseX - cx;
targetY = mouseY - cy;
}
private var targetScale:Number = 0;
private var targetX:Number = 0;
private var targetY:Number = 0;
private var targetRotation:Number = 0;
private var currentScale:Number = 0;
private var currentX:Number = 0;
private var currentY:Number = 0;
private var currentRotation:Number = 0;
private var easeStrong:Number = 0.10;
private function fill():void{
currentScale += ( targetScale - currentScale ) * easeStrong;
currentRotation += ( targetRotation - currentRotation ) * easeStrong;
currentX += ( targetX - currentX ) * easeStrong;
currentY += ( targetY - currentY ) * easeStrong;
matrix.a = matrix.d = 1;
matrix.b = matrix.c = 0;
matrix.a = matrix.d = currentScale;
matrix.rotate( currentRotation );
matrix.tx = currentX;
matrix.ty = currentY;
canvas.graphics.clear();
canvas.graphics.beginBitmapFill( source, matrix, true, false );
canvas.graphics.drawRect( -cx, -cy, sw, sh );
canvas.graphics.endFill();
}
public function stopBitmapFill():void {
removeEventListener( Event.ENTER_FRAME, fill );
}
public var sw:Number;
public var sh:Number;
public var cx:Number;
public var cy:Number;
public function resizeHandler( e:Event = null ):void {
sw = stage.stageWidth;
sh = stage.stageHeight;
cx = sw/2>>0;
cy = sh/2>>0;
}
}
}
import flash.events.*;
import flash.display.*;
import flash.system.*;
import flash.net.*;
class MikanLoader extends EventDispatcher {
public var data:BitmapData;
private var _loader:Loader;
public function MikanLoader(){
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener( Event.COMPLETE, _loaderCompleteHandler );
}
private function _loaderCompleteHandler(e:Event):void {
_loader.contentLoaderInfo.removeEventListener( Event.COMPLETE, _loaderCompleteHandler );
data = Bitmap(_loader.content ).bitmapData;
_loader = null;
dispatchEvent( new Event( Event.COMPLETE ) );
}
private var _imgSrc:String = "http://assets.wonderfl.net/images/related_images/b/b8/b8cc/b8cc9050bc9cf3915a0de6537e7f9b0bc29f2c11";
public function load():void {
var url:URLRequest = new URLRequest( _imgSrc );
_loader.load( url, new LoaderContext(true) );
}
}