In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

けいおん!EDのアレ

けいおん!EDのアレ
* @author dkgkAs
* @see http://d.hatena.ne.jp/ActionScript/20090602/flash_wonderfl_keion_ed
* @since 2009.06.02
* 
* Smart Gradient API
* @see http://blog.jactionscripters.com/2009/05/31/smart-gradient-api/
* 
* 2009.06.04 delayの仕方について正しい方法をBeInteractive!さんに教えていただいたので修正を加えました。
* 詳しくはブログに書いてあります。
/**
 * Copyright dkgkAs ( http://wonderfl.net/user/dkgkAs )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vHzT
 */

/**
 * けいおん!EDのアレ
 * @author dkgkAs
 * @see http://d.hatena.ne.jp/ActionScript/20090602/flash_wonderfl_keion_ed
 * @since 2009.06.02
 * 
 * Smart Gradient API
 * @see http://blog.jactionscripters.com/2009/05/31/smart-gradient-api/
 * 
 * 2009.06.04 delayの仕方について正しい方法をBeInteractive!さんに教えていただいたので修正を加えました。
 * 詳しくはブログに書いてあります。
 */

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.text.TextField;
	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.easing.Linear;
	import org.libspark.betweenas3.easing.Quint;
	import org.libspark.betweenas3.tweens.ITween;
	
	[SWF(width = 465, height = 465, backgroundColor = 0x000000, frameRate = 30)]
	
	public class KeionEDLamp extends Sprite
	{
		private var _scx:Number = stage.stageWidth  * 0.5;
		private var _scy:Number = stage.stageHeight  * 0.5;
		private var _txt:TextField = new TextField();
		
		private var _lampVector:Vector.<Lamp> = new Vector.<Lamp>();
		private var _lampNumber:Number = 5;
		private var _lampMargin:Number = 101;
		
		public function KeionEDLamp()
		{
			addEventListener(Event.ADDED_TO_STAGE, initialize);
		}
		
		private function initialize(event:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, initialize);
			
			var bg:Sprite = new Sprite();
			bg.graphics.beginFill(0x202020);
			bg.graphics.drawRect( 0, 60, stage.stageWidth, stage.stageHeight - 120);
			bg.graphics.endFill();
			addChild(bg);
			
			for (var i:int = 0; i < _lampNumber; i++) 
			{ 
				_lampVector.push(addNewLamp(i * _lampMargin + 30));
			}
			
			_txt.text = "Click to Start";
			_txt.textColor = 0xFFFFFF;
			addChild(_txt);
			
			stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
		}
		
		private function mouseUpHandler(event:MouseEvent):void 
		{
			var tween1:Array = [];
			var tween2:Array = [];
			var length:int = _lampVector.length;
			
			for (var i:int = 0; i < length; i++) 
			{ 
				tween1[i] = ITween(BetweenAS3.tween(_lampVector[i].blurSprite, { alpha:1.0, _blurFilter: { blurX: 76, blurY: 76 }}, { alpha:0, _blurFilter: { blurX: 32, blurY: 32 }}, 0.15));
				tween1[i] = ITween(BetweenAS3.serial(tween1[i], BetweenAS3.reverse(tween1[i])));
				tween1[i] = BetweenAS3.repeat(tween1[i], 2);
				
				/* 最初に書いていたダメなdelayの仕方
				delayTween = BetweenAS3.tween(new Sprite(), { x:0 }, null, 0.1);
				tween1[i] = BetweenAS3.serial(delayTween, tween1[i]);
				*/
				
				tween1[i] = BetweenAS3.delay(tween1[i], 0.1); // これでオッケー
			}
				
			for (var j:int = 0; j < length; j++) 
			{ 
				var fillTween:ITween = BetweenAS3.tween(_lampVector[j].fillSprite, { alpha:1.0 }, { alpha:0 }, 0.15);
				var blurTween:ITween = BetweenAS3.tween(_lampVector[j].blurSprite, { alpha:1.0, _blurFilter: { blurX: 76, blurY: 76 }}, { alpha:0, _blurFilter: { blurX: 32, blurY: 32 }}, 0.15, Quint.easeIn);
				tween2[j] = BetweenAS3.parallel(fillTween, blurTween);
				tween2[j] = BetweenAS3.serial(tween2[j], BetweenAS3.reverse(tween2[j]));
				
				var delay:Number = ((length - 1) - j) * 0.06;
				
				/* 最初に書いていたダメなdelayの仕方
				delayTween = BetweenAS3.tween(new Sprite(), { x:0 }, { x:0 }, delay);
				tween2[j] = BetweenAS3.serial(delayTween, tween2[j], tween2[j]);
				*/
				
				tween2[j] = BetweenAS3.repeat(tween2[j], 2);
				tween2[j] = BetweenAS3.delay(tween2[j], delay); // これでオッケー
			}
			
			var t1:ITween = BetweenAS3.parallel.apply(null, tween1);
			var t2:ITween = BetweenAS3.parallel.apply(null, tween2);
			BetweenAS3.serial(t1, t2).play();
		}
		
		private function addNewLamp(x:Number):Lamp
		{
			var lamp:Lamp = new Lamp();
			lamp.x = x;
			lamp.y = _scy;
			addChild(lamp);
			
			return lamp;
		}
	}
}

import flash.display.*;
import flash.geom.*;

internal class Lamp extends Sprite
{
	public var baseSprite:Sprite;
	public var fillSprite:Sprite;
	public var blurSprite:Sprite;
	
	public function Lamp()
	{
		baseSprite = new Sprite();
		SmartGradient.beginRadialGradientFill(baseSprite, [0x400000, 0x100000], [0.8, 1], [130, 255], new Point(0, 0), 32);
		with (baseSprite)
		{
			graphics.drawCircle(0, 0, 32);
			graphics.endFill();
		}
		addChild(baseSprite);
		
		
		fillSprite = new Sprite();
		SmartGradient.beginRadialGradientFill(fillSprite, [0xE53246, 0xAF1021], [0.8, 0.3], [100, 255], new Point(0, 0), 32);
		with (fillSprite) 
		{
			graphics.drawCircle(0, 0, 32);
			graphics.endFill();
			alpha = 0;
		}
		addChild(fillSprite);
		
		blurSprite = new Sprite();
		with (blurSprite) 
		{
			graphics.beginFill(0xFF0000, 1.0);
			graphics.drawCircle(0, 0, 32);
			graphics.endFill();
			alpha = 0;
		}
		addChild(blurSprite);
	}
}

import flash.display.GradientType;
import flash.display.InterpolationMethod;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.geom.Point;

internal class SmartGradient
{
	public static function beginRadialGradientFill(target:Sprite, colors:Array, alphas:Array, ratios:Array, centerPoint:Point, radius:Number, spreadMethod:String = null, interpolationMethod:String = null):void
	{
		spreadMethod ||= SpreadMethod.PAD;
		interpolationMethod ||= InterpolationMethod.RGB;
		
		var mat:Matrix = new Matrix();
		mat.createGradientBox(radius * 2, radius * 2, 0, centerPoint.x - radius, centerPoint.y - radius);
		target.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, mat, spreadMethod, interpolationMethod);
	}

	public static function beginLinearGradientFill(target:Sprite, colors:Array, alphas:Array, ratios:Array, startPoint:Point, endPoint:Point, spreadMethod:String = null, interpolationMethod:String = null):void
	{
		spreadMethod ||= SpreadMethod.PAD;
		interpolationMethod ||= InterpolationMethod.RGB;
		
		var dx:Number = endPoint.x - startPoint.x;
		var dy:Number = endPoint.y - startPoint.y;
		var dist:Number = Math.sqrt(dx * dx + dy * dy);
		var rad:Number = Math.atan2(dy, dx);
		var offsetX:Number = -(dist - Math.cos(rad) * dist) * 0.5 + startPoint.x;
		var offsetY:Number = -(dist - Math.sin(rad) * dist) * 0.5 + startPoint.y;
		var mat:Matrix = new Matrix();
		mat.createGradientBox(dist, dist, rad, offsetX, offsetY);
		target.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, mat, spreadMethod, interpolationMethod);
	}
}