hello it's me
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.utils.getTimer;
[SWF(width="465", height="465", backgroundColor="0xeeeeee", frameRate="24")]
/**
*
*/
public class Main2 extends MovieClip
{
// _____________________________________________________ Property
private static const LOGO_URI:String = "http://ppworks.jp/swf/assets/27750.jpg";
//private static const LOGO_URI:String = "http://ppworks.jp/swf/assets/nightview.jpg";
private static const PERTICLE_SIZE:uint = 6;
private var _logo:Bitmap;
private var _particles:Array = [];
private var _prevTime:Number;
private var _center:Point;
private var _gather:Boolean;
private var _complete:Boolean;
// _____________________________________________________ Method
public function Main2()
{
loadLogo();
}
private function loadLogo():void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteListener);
loader.load(new URLRequest(LOGO_URI), new LoaderContext(true));
}
private function analyzeLogoBitmap():void
{
for (var i:uint = 0; i < _logo.width/PERTICLE_SIZE; i++)
{
for (var j:uint = 0; j < _logo.height/PERTICLE_SIZE; j++)
{
var bitmapData:BitmapData = new BitmapData(PERTICLE_SIZE, PERTICLE_SIZE, true, _logo.bitmapData.getPixel32(i * PERTICLE_SIZE + PERTICLE_SIZE/2, j * PERTICLE_SIZE + PERTICLE_SIZE/2));
var bitmap:Bitmap = new Bitmap(bitmapData);
var origin:Point = new Point(
i * PERTICLE_SIZE + stage.stageWidth/2 - _logo.width/2,
j * PERTICLE_SIZE + stage.stageHeight/2 - _logo.height/2
);
bitmap.x = Math.random() * stage.stageWidth;//origin.x;
bitmap.y = Math.random() * stage.stageHeight;//origin.y;
addChild(bitmap);
_particles.push( {
bitmap:bitmap,
origin:origin,
speed:new Point(0, 0),
acc:new Point(0, 0)
});
}
}
addChild(_logo);
_center = new Point(stage.stageWidth/2, stage.stageHeight/2);
_prevTime = getTimer();
addEventListener(Event.ENTER_FRAME, enterFrameListener);
stage.addEventListener(MouseEvent.CLICK, clickListener);
}
// _____________________________________________________ Listener
private function loadCompleteListener(event:Event):void
{
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
loaderInfo.removeEventListener(Event.COMPLETE, arguments.callee);
_logo = loaderInfo.loader.content as Bitmap;
_logo.x = stage.stageWidth/2 -_logo.width / 2;
_logo.y = stage.stageHeight/2 -_logo.height / 2;
_logo.alpha = 0;
analyzeLogoBitmap();
}
private function enterFrameListener(event:Event):void
{
var t:Number = (getTimer() - _prevTime) / 1000;
var completeCount:uint;
if (_gather && _complete)
{
_logo.alpha += (1 - _logo.alpha) / 16;
}
else
{
_logo.alpha = 0;
}
for each (var particle:Object in _particles)
{
var acc:Number;
var radian:Number;
if (_gather) {
acc = Math.random() * 3000;
radian = Math.atan2(particle.origin.y - particle.bitmap.y, particle.origin.x - particle.bitmap.x);
if (completeCount / _particles.length >= 0.99)
{
_complete = true;
}
else
{
_complete = false;
}
if (Point.distance(particle.origin, new Point(particle.bitmap.x, particle.bitmap.y)) < 3)
{
particle.bitmap.x = particle.origin.x;
particle.bitmap.scaleX = 1;
particle.bitmap.y = particle.origin.y;
particle.bitmap.scaleY = 1;
completeCount++;
continue;
}
else if (Point.distance(particle.origin, new Point(particle.bitmap.x, particle.bitmap.y)) > 20)
{
particle.acc.x += 100 * Math.cos(Math.random());
particle.acc.y += 100 * Math.cos(Math.random());
}
}
else
{
_complete = false;
acc = Math.random() * 2000;
radian = Math.random() * Math.PI * 2;
}
particle.acc.x += acc * Math.cos(radian);
particle.acc.y += acc * Math.sin(radian);
particle.bitmap.x += particle.speed.x * t + 0.5 * particle.acc.x * Math.pow(t, 2);
particle.bitmap.y += particle.speed.y * t + 0.5 * particle.acc.y * Math.pow(t, 2);
particle.bitmap.scaleX = Math.random();
particle.bitmap.scaleY = Math.random();
particle.speed.x += (particle.acc.x * t);
particle.speed.y += (particle.acc.y * t);
particle.speed.x *= 0.9;
particle.speed.y *= 0.9;
particle.acc.x = 0;
particle.acc.y = 0;
}
_prevTime = getTimer();
}
private function clickListener(event:MouseEvent):void
{
_gather = !_gather;
_logo.x = mouseX - _logo.width/2;
_logo.y = mouseY - _logo.height / 2;
_logo.alpha = 0;
if (!_gather) {
for each (var particle:Object in _particles)
{
particle.acc.x += 2000 * Math.cos(Math.random());
particle.acc.y += 2000 * Math.sin(Math.random());
}
return;
}
for (var i:uint = 0; i < _logo.width/PERTICLE_SIZE; i++)
{
for (var j:uint = 0; j < _logo.height/PERTICLE_SIZE; j++)
{
_particles[j + i *(_logo.height/PERTICLE_SIZE)].origin = new Point(
i * PERTICLE_SIZE + mouseX - _logo.width/2,
j * PERTICLE_SIZE + mouseY - _logo.height/2
);
}
}
}
}
}