テスト

by Nyarineko
♥0 | Line 61 | Modified 2009-09-30 15:11:50 | MIT License
play

ActionScript3 source code

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

package {

    import flash.display.Sprite;
	import flash.events.Event;
	import org.libspark.betweenas3.easing.*;
	

    [SWF(backgroundColor="#FFFFFF", frameRate=30)]
    public class FlashTest extends Sprite {

		private var _gradation:Gradation;
				
		private var _circle:Sprite = new Sprite();
		private var _c:uint;
		private var _f:Boolean = false;
		
        public function FlashTest() {
			_gradation = new Gradation(0xcc0000, 0xcc6000, 0xcccc00, 0x00cc00, 0x00cccc, 0x0000cc, 0x6000cc);
			_gradation.setEasing(Linear.easeNone);
			addEventListener(Event.ENTER_FRAME, _update);
			
			addChild(_circle);
        }
		
		private function _update(e:Event):void
		{
		    var cor:Number = 255;
			_circle.graphics.clear();
			_circle.graphics.beginFill(_gradation.getColor(_c / cor));
			_circle.graphics.drawCircle(0, 0, 50);
			_circle.x = 230;
			_circle.y = 230;
            if(_c >= cor) _c = 0;
            _c ++;
		}
    }
}

//--------------------------------------------------
//1ファイル内にクラスを3つ以上作成するとCS4でビルドできなくなるバグ対策クラス
internal class EmptyClass { }

//--------------------------------------------------
/**
 * @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 extends EmptyClass
{
	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);
		}
	}
}