flash on 2013-2-2
♥0 |
Line 158 |
Modified 2013-02-07 09:21:03 |
MIT License
archived:2017-03-20 14:07:53
ActionScript3 source code
/**
* Copyright ohisama ( http://wonderfl.net/user/ohisama )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/imok
*/
package
{
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.system.*;
import flash.text.*;
import flash.filters.*;
import flash.geom.*;
import flash.utils.*;
import flash.media.Sound;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.events.AsyncErrorEvent;
import flash.events.Event;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
import flash.filters.GlowFilter;
import flash.filters.GradientGlowFilter;
import flash.filters.BlurFilter;
import flash.filters.BitmapFilterQuality;
import flash.utils.*;
import flash.geom.Point;
import net.hires.debug.Stats;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.*;
import org.libspark.betweenas3.tweens.ITween;
[SWF (backgroundColor='#000000', frameRate=30)]
public class test10 extends Sprite
{
private static var P_ZERO : Point = new Point();
private static var F_BLUR : BlurFilter = new BlurFilter(4, 4, BitmapFilterQuality.LOW);
private var _film : BitmapData;
//private var _timer : Timer;
private var _activeParticles : Vector.<Particle>;
private var _inactiveParticles : Vector.<Particle>;
private var sound : Sound;
private var loader : Loader = new Loader();
public function test10()
{
loader.load(new URLRequest("http://www5b.biglobe.ne.jp/~pengin1/mqo/yoru1.jpg"), new LoaderContext(true));
addChild(loader);
//stage.addChild(new Stats());
var bm : Bitmap;
_activeParticles = new Vector.<Particle>();
_inactiveParticles = new Vector.<Particle>();
_film = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0xe0000000);
bm = new Bitmap(_film);
var soundReq : URLRequest;
soundReq = new URLRequest("http://www5b.biglobe.ne.jp/~pengin1/mqo/hanabi.mp3");
sound = new Sound(soundReq);
sound.play();
addChild(bm);
//_timer = new Timer(100);
//_timer.addEventListener(TimerEvent.TIMER, timerHandler);
//_timer.start();
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
stage.addEventListener(MouseEvent.MOUSE_DOWN, on_MouseDown);
//stage.addEventListener(MouseEvent.MOUSE_UP, on_MouseUp);
}
private function enterFrameHandler(event : Event) : void
{
var i : uint;
var p : Particle;
_film.lock();
_film.applyFilter(_film, _film.rect, P_ZERO, F_BLUR);
for (i = 0; i < _activeParticles.length; i++)
{
p = _activeParticles[i];
p.x += p.vx;
p.y += p.vy;
p.life--;
_film.setPixel32(p.x, p.y, p.color);
if (!p.life)
{
_activeParticles.splice(i, 1);
_inactiveParticles.push(p);
i--;
}
}
_film.unlock();
}
//private function timerHandler(evt : TimerEvent) : void
private function on_MouseDown(event : MouseEvent) : void
{
//_timer.delay = (3100 + Math.random() * 950) >> 0;
sound.play();
var sp : Sprite;
var bm : Bitmap;
var bmd : BitmapData;
var t : ITween;
bmd = new BitmapData(10, 10, true, 0xfdf00f00);
bm = new Bitmap(bmd);
bm.smoothing = true;
bm.x -= bm.width >> 1;
bm.y -= bm.height >> 1;
sp = new Sprite();
sp.addChild(bm);
//sp.x = (Math.random() * stage.stageWidth) >> 0;
//sp.y = (Math.random() * stage.stageHeight) >> 0;
sp.x = mouseX;
sp.y = mouseY;
sp.scaleX = 0;
sp.scaleY = 0;
sp.rotation = (Math.random() * 360) >> 0;
t = BetweenAS3.serial(BetweenAS3.to(sp,
{
scaleX : 2,
scaleY : 2,
rotation : 0
}, 0, Expo.easeIn), BetweenAS3.removeFromParent(sp));
t.onComplete = tweenComplete;
t.onCompleteParams = [sp, bm, bmd];
t.play();
}
private function tweenComplete(sp : Sprite, bm : Bitmap, bmd : BitmapData) : void
{
var i : uint;
var j : uint;
var c : uint;
var cx : Number;
var cy : Number;
var angle : Number;
var strength : Number;
var p : Particle;
cx = sp.x + bm.x;
cy = sp.y + bm.y;
for (i = 0; i < bmd.width; i++)
{
for (j = 0; j < bmd.height; j++)
{
c = bmd.getPixel32(i, j) + 100;
if (!c) continue;
p = _inactiveParticles.length ? _inactiveParticles.shift() : new Particle();
angle = Math.random() * Math.PI * 2;
strength = Math.random() * 20;
p.vx = Math.cos(angle) * strength;
p.vy = Math.sin(angle) * strength;
p.x = cx + i;
p.y = cy + j;
p.color = c;
p.life = 10;
_activeParticles.push(p);
}
}
bmd.dispose();
var flash : Sprite = new Sprite()
flash.graphics.beginFill(0xFFFFFF)
flash.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight)
flash.blendMode = BlendMode.OVERLAY
flash.alpha = 0
BetweenAS3.serial(BetweenAS3.addChild(flash, this), BetweenAS3.tween(flash, {alpha : 0}, {alpha : 1}, 0.3, Sine.easeIn), BetweenAS3.removeFromParent(flash)).play()
}
}
}
class Particle
{
public var vx : Number;
public var vy : Number;
public var x : Number;
public var y : Number;
public var color : uint;
public var life : uint;
}