forked from: 【AS100本ノック】2回目:たま

by mex_ny forked from 【AS100本ノック】2回目:たま (diff: 185)
AS100本ノック
* 2回目のお題は「たま」
* あなたなりの「たま」を表現してください。
* 
*  たま = 弾
*  ↓
* 「弾幕薄いぞ! 何やってる!」by 某大佐
*  ↓ 
*  弾幕張ってみました
♥0 | Line 146 | Modified 2010-11-01 22:03:00 | MIT License
play

ActionScript3 source code

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

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

// forked from mex's 【AS100本ノック】2回目:たま
/* 
 * AS100本ノック
 * 2回目のお題は「たま」
 * あなたなりの「たま」を表現してください。
 * 
 *  たま = 弾
 *  ↓
 * 「弾幕薄いぞ! 何やってる!」by 某大佐
 *  ↓ 
 *  弾幕張ってみました
 */

package {
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.geom.Point;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import org.libspark.betweenas3.easing.Quint;
    
    public class Tama extends Sprite
    {
        private const CIRCLE_MAX_NUM:uint = 40,RADIUS:uint = 0,ADD_GRAD_VALUE:Number = 0.01 , BASE_POINT:Point = new Point( 0 , 0 );
        private var _width:uint,_height:uint,_effectLayer:Sprite = new Sprite();
        private var _center:Point,_startAngle:uint = 0,_counter:Number = 0,_buffer:Vector.<Bullet> = new Vector.<Bullet>();
        private var _gradation:Gradation,_isAdd:Boolean = true;
     
        public function Tama()
        {
            _width = 465;
            _height = 465;
            var bmpData:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,false, 0x000000);
            addChild(new Bitmap( bmpData ));
            
            Wonderfl.capture_delay( 3 );
            
            init();
        }
        
        private function init():void
        {
            _effectLayer.filters = [ new BlurFilter( 8 , 8 , 2 ) ];
            _center = new Point( stage.stageWidth / 2 , stage.stageHeight / 2 );
            addChild( _effectLayer );
            
            _gradation = new Gradation( 0xFF0000, 0xFF8000 , 0xFFFF00, 0x00FF00, 0x0000FF, 0x9900FF , 0xFF00FF );
            _gradation.setEasing( Quint.easeInOut );
            
            var timer:Timer = new Timer( 150 );
            timer.addEventListener( TimerEvent.TIMER , drawCricleTimer );
            timer.start ();
        }
        
        private function drawCricleTimer( e:TimerEvent ):void
        {
            drawCricle();
        }
        
        private function drawCricle():void
        {
            var bullet:Bullet, base_angle:uint = 360 / CIRCLE_MAX_NUM, angle:Number = 0, color:uint = _gradation.getColor (_counter), startPoint:Point = BASE_POINT;
            var addValue:Number = ( _isAdd ) ? ADD_GRAD_VALUE : ADD_GRAD_VALUE * -1;
            if ( _counter + addValue > 1 ) _isAdd = false;
            if ( _counter + addValue < 0 ) _isAdd = true;
            addValue = ( _isAdd ) ? ADD_GRAD_VALUE : ADD_GRAD_VALUE * -1;
            _counter += addValue;
            
            startPoint.x = 50 * Math.cos( angle2radian( _startAngle ) ) + _center.x;
            startPoint.y = 50 * Math.sin( angle2radian( _startAngle ) ) + _center.y;
            
            for ( var i:uint = 0; i < CIRCLE_MAX_NUM; i++ )
            {
                if ( _buffer.length )
                {
                    bullet = _buffer.shift();
                    bullet.setColor( color );
                }
                else
                    bullet = new Bullet( color );

                _effectLayer.addChildAt( bullet , 0 );
                bullet._center_x = startPoint.x;
                bullet._center_y = startPoint.y;
                bullet.x = RADIUS * Math.cos( angle2radian( angle ) ) + bullet._center_x;
                bullet.y = RADIUS * Math.sin( angle2radian( angle ) ) + bullet._center_y;
                bullet._angle = angle;
                bullet._radius = RADIUS;
                bullet.addEventListener( Event.ENTER_FRAME , eventLoopHandler );
                angle += base_angle;
            }
            
            _startAngle += 20;
            if ( _startAngle >= 360 ) _startAngle = 0;
        }

     	private function eventLoopHandler( e:Event ):void
		{
	        var bullet:Bullet = e.target as Bullet,angle:Number = bullet._angle,radius:uint = bullet._radius;   
       	    angle += 3;
       	    radius += 3;
       	    bullet.x = radius * Math.cos( angle2radian( angle ) ) + bullet._center_x;
       	    bullet.y = radius * Math.sin( angle2radian( angle ) ) + bullet._center_y;
       	    bullet._angle = angle;
       	    bullet._radius = radius;
           	     
       	    if ( bullet.x < -50 || bullet.x >_width + 50 || bullet.y < -50 || bullet.y >_height + 50 )
       	    {
       	        _effectLayer.removeChild( bullet );
       	        bullet.removeEventListener( Event.ENTER_FRAME , eventLoopHandler );
       	        _buffer.push( bullet );
           	}
           	 
       	    if ( angle >= 360 ) angle = 0;
       }

       private function angle2radian( angle:int ):Number
       {
           return angle * Math.PI / 180;
       }
  
    }
}

import flash.display.Graphics;
import flash.display.Shape;
import flash.geom.ColorTransform;
class Bullet extends Shape
{
    public var _angle:Number, _radius:uint, _center_x:uint, _center_y:uint;
 
    public function Bullet( color:uint )
    {
        var g:Graphics = graphics;
        g.beginFill( color , 1 );
        g.drawCircle( 0, 0,  30 );
        g.endFill();
    }
    
    public function setColor( c:uint ):void
    {
        var color:ColorTransform = new ColorTransform ( 0, 0, 0, 1, ( c & 0xff0000 ) >> 16 , ( c & 0xff00 ) >> 8 , ( c & 0xff )  , 0 );
		transform.colorTransform = color;
    }
       
}

/**
 * @author saqoosha
 * @see http://wonderfl.net/code/7ed2d650b9d513edf9a499fb704c19ecb7aa4694
 */
 
import frocessing.color.ColorLerp;
import org.libspark.betweenas3.core.easing.IEasing;
import org.libspark.betweenas3.easing.Linear;
class Gradation
{
     private var _colors:Array;
     private var _easing:IEasing;
        
     public function Gradation(...args):void
     {
         _colors = args.concat();
         _easing = Linear.linear;
     }
     
     public function setEasing(easing:IEasing):void
     {
         _easing = easing;
     }
     
     public function getColor(position:Number):uint
     {
         position = (position < 0 ? 0 : position > 1 ? 1 : position) * (_colors.length - 1);
         var idx:int = position;
         var alpha:Number = _easing.calculate(position - idx, 0, 1, 1);
         if (alpha == 0)
         {
             return _colors[idx];
         }
         else
         {
             return ColorLerp.lerp(_colors[idx], _colors[idx + 1], alpha);
         }
     }
}