花火
今、僕に出来る花火。
/**
* Copyright kuma360 ( http://wonderfl.net/user/kuma360 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1wEV
*/
//今、僕に出来る花火。
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
import flash.geom.Point;
public class Main extends Sprite
{
private var _plane1:BitmapData = new BitmapData ( 465 , 465 , true , 0x50000000 ) ;
private var _plane2:BitmapData = new BitmapData ( 465 , 465 , true , 0x30000000 ) ;
private var _screen:BitmapData = new BitmapData ( 465 , 465 , false , 0 ) ;
private var _effect:BitmapData = new BitmapData ( 465 , 465 , false , 0 ) ;
private var _canvas:BitmapData = new BitmapData ( 465 , 465 , false , 0 ) ;
private var _CB:Bitmap = new Bitmap ( _canvas ) ;
private var _buf:Vector.<particle> = new Vector.<particle> ( ) ;
public function Main():void
{
addChild ( _CB ) ;
particle.create_visual ( ) ;
var CLICK:Boolean = false ;
stage.addEventListener ( MouseEvent.CLICK , function ( e:Event ) :void { CLICK = true ; } ) ;
addEventListener (
Event.ENTER_FRAME ,
function ( e:Event ) :void {
var D:particle ;
_screen.lock() ;
_canvas.lock() ;
_effect.lock() ;
_screen.applyFilter ( _screen , _screen.rect , new Point , new BlurFilter ( 5 , 5 , 2 ) ) ;
_screen.copyPixels ( _plane2 , _plane2.rect , new Point ) ;
if ( CLICK ) {
CLICK = false ;
for ( var I:int = 0 ; I < 140 ; ++ I ) {
_buf.push ( new particle ( mouseX , mouseY , I ) ) ;
}
}
for each ( D in _buf ) {
D.update ( ) ;
}
for each ( D in _buf ) {
D.render ( _screen ) ;
}
_effect.applyFilter ( _canvas , _canvas.rect , new Point , new BlurFilter ( 10 , 10 , 5 ) ) ;
_effect.copyPixels ( _plane1 , _plane1.rect , new Point ) ;
_canvas.fillRect ( _canvas.rect , 0 ) ;
_canvas.draw ( _screen ) ;
_canvas.draw ( _effect , null , null , "add" ) ;
_effect.unlock() ;
_canvas.unlock() ;
_screen.unlock() ;
for ( var K:int = 0 ; K < _buf.length ; ++ K ) {
if ( _buf[K].die ) {
_buf.splice ( K , 1 ) ;
}
}
}
) ;
}
}
}
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.geom.Point;
class particle {
private static var _B:BitmapData = new BitmapData ( 4 , 4 , true , 0 ) ;
public static function create_visual ( ) :void {
var M:Matrix = new Matrix ;
var S:Sprite = new Sprite ;
var G:Graphics = S.graphics ;
M.createGradientBox ( 4 , 4 ) ;
G.beginGradientFill ( "radial" , [ 0x90F060 , 0x908080 ] , [ 1 , 0 ] , [ 0 , 255 ] , M ) ;
G.drawRect ( 0 , 0 , 4 , 4 ) ;
G.endFill ( ) ;
_B.draw ( S ) ;
}
private var _x:Number ;
private var _y:Number ;
private var _vx:Number ;
private var _vy:Number ;
private var _l:Number ;
private var _die:Boolean = false ;
public function particle ( x:Number , y:Number , cnt:int ) {
_x = x ;
_y = y ;
var X:Number = Math.cos ( Math.random() * 360 * Math.PI / 180 ) ;
var Y:Number = Math.sin ( Math.random() * 360 * Math.PI / 180 ) ;
var L:Number = Math.sqrt ( X * X + Y * Y ) ;
if ( L ) { L = 1 / L ; }
X *= L ;
Y *= L ;
X *= Math.floor ( cnt / 20 ) + .1 + Math.random() ;
Y *= Math.floor ( cnt / 20 ) + .1 + Math.random() ;
X *= 1.4 ;
Y *= 1.4 ;
_vx = X ;
_vy = Y ;
_l = Math.random() * 7 + 30 ;
_die = false ;
}
public function update ( ) :void {
_x += _vx ;
_y += _vy ;
_vx *= .9 ;
_vy *= .9 ;
_vy += .01 ;
_die = ( -- _l < 0 ) ;
}
public function render ( canvas:BitmapData ) :void {
canvas.copyPixels ( _B , _B.rect , new Point ( _x , _y ) ) ;
}
public function get die ( ) :Boolean {
return _die ;
}
}