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

HeartMark

Get Adobe Flash player
by inosyan 15 Feb 2009
    Embed
package {
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	[SWF(width='465', height='465', backgroundColor='#103860', frameRate='30')]
	public class HeartMark extends Sprite
	{
		private var _spMain:Sprite;
		private var enterFrameFunc:Function;
		private var _deg:Number = 0;
		public function HeartMark()
		{
			var spMain:Sprite = new Sprite;
			_spMain = spMain;
			drawHeart(spMain);
			enterFrameFunc = enterFrameHeart;
			spMain.x = stage.stageWidth/2 - spMain.width/2;
			spMain.y = 10;
			addChild(spMain);
			
			this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			
			// ボタン作成
			const MARGIN:int = 10;
			const BTN_HEIGHT:int = 65;
			const TOTALCNT:int = 4;
			var LEFT:int = (stage.stageWidth - BTN_HEIGHT * TOTALCNT - MARGIN * (TOTALCNT - 1)) / 2;
			var posY:Number = stage.stageHeight - BTN_HEIGHT - MARGIN;

			_makeBtn(
				drawHeart,
				function(e:Event):void
				{
					_deg = 0;
					enterFrameFunc = enterFrameHeart;
				});

			_makeBtn(
				drawPeach,
				function(e:Event):void
				{
					_deg = 0;
					enterFrameFunc = enterFramePeach;
				});
				
			_makeBtn(
				drawInfinity,
				function(e:Event):void
				{
					_deg = 0;
					enterFrameFunc = enterFrameInfinity;
				});
				
			_makeBtn(
				drawInfinity2,
				function(e:Event):void
				{
					_deg = 0;
					enterFrameFunc = enterFrameInfinity2;
				});
				
			var btncnt:int = 0;
			function _makeBtn(drawFunc:Function, func:Function):void
			{
				var sp:Sprite = new Sprite;
				drawFunc(sp);
				sp.x = LEFT + (BTN_HEIGHT + MARGIN)*btncnt;
				sp.y = posY;
				sp.width = sp.height = BTN_HEIGHT;
				addChild(sp);
				sp.addEventListener(MouseEvent.CLICK, func);
				++btncnt;
			}
			
		}
		
		private function onEnterFrame(e:Event):void
		{
			 _deg += 5;
			enterFrameFunc();
		}
		
		private function getRate():Number
		{
			return Math.abs(Math.sin(_deg / 180 * Math.PI));
		}
		
		
		private function enterFrameHeart():void{
			drawHeart(_spMain, getRate());
		}

		private function enterFramePeach():void{
			drawPeach(_spMain, getRate());
		}

		private function enterFrameInfinity():void{
			drawInfinity(_spMain, getRate());
		}
		
		private function enterFrameInfinity2():void{
			drawInfinity2(_spMain, getRate());
		}
		
		private function drawTemplate(sp:Sprite, getRFunc:Function):void
		{
			var g:Graphics = sp.graphics;
			g.clear();
			g.lineStyle(0);
			g.beginFill(0xffffff);
			g.drawRect(0,0,300,300);
			g.endFill();
			
			const SCALE:int = 80;
			var r:Number = 0.0, theta:Number = 0.0;
			g.lineStyle();
			for(var i:int=-Math.PI*8; i<=Math.PI*8; i++) {
				theta = i/8;
				r = getRFunc(theta);
				var posX:Number = SCALE*r*Math.sin(theta) + sp.width/2;
				var posY:Number = SCALE*r*Math.cos(theta) + sp.height/2;
				g.beginFill(0xff007f, 0.5);
				g.drawCircle(posX, posY, 4);
				g.endFill();
			}		
			
		}
		
		private function drawHeart(sp:Sprite, rate:Number = 0):void
		{
			drawTemplate(sp, _getR);
			function _getR(theta:Number):Number
			{
				return Math.pow(Math.sin(Math.abs(theta)), Math.abs(theta)/(1 + rate * 6));
			}
		}
		
		private function drawPeach(sp:Sprite, rate:Number = 0):void
		{
			drawTemplate(sp, _getR);
			function _getR(theta:Number):Number
			{
				return Math.abs(theta)*0.3 * (1 - rate) + 0.3;
			}
		}

		private function drawInfinity(sp:Sprite, rate:Number = 0):void
		{
			drawTemplate(sp, _getR);
			function _getR(theta:Number):Number
			{
				return Math.sin(Math.abs(theta)*(1-rate));
			}
		}

		private function drawInfinity2(sp:Sprite, rate:Number = 0):void
		{
			drawTemplate(sp, _getR);
			function _getR(theta:Number):Number
			{
				return Math.pow(Math.sin(Math.abs(theta)), 5*(1-rate));
			}
		}

	}
}