forked from: PentagonalStar++ by click

by hacker_9p8x8mco forked from PentagonalStar++ by click (diff: 53)
♥0 | Line 56 | Modified 2010-04-29 09:33:33 | MIT License
play

ActionScript3 source code

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

package{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class PentagonalStar extends Sprite{
		private var _arrayStar:Array = [];
		private var _arrayRotation:Array = [];
		
		public function PentagonalStar(){
			this.addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
		}

		private function init(e:Event):void{
			this.removeEventListener(Event.ADDED_TO_STAGE,init);
			var tm:TextFormat = new TextFormat();
			tm.bold = true;
			tm.font = "Gothic";
			tm.size = 20;
			var tf:TextField = new TextField();
			tf.defaultTextFormat = tm;
			tf.width = 300;
			tf.text = "More Click\nanywhere!!";
			tf.x = stage.stageWidth/2;
			tf.y = stage.stageHeight/2;
			this.stage.addChild(tf);

			var star:Sprite = new Sprite();
			createStar(200,200,50,star);
			this.stage.addEventListener(MouseEvent.CLICK,goToCreateStar,false,0,true);
		}
		
		private function goToCreateStar(e:MouseEvent):void{
			var star:Sprite = new Sprite();
			createStar(mouseX,mouseY,100 * (Math.random() * 0.5 + 0.5),star);
		}


		private function createStar(x:int,y:int,radius:int,star:Sprite):void{
			star.graphics.lineStyle(2,(Math.random() * 0.9 + 0.1) * 0xffffff,Math.random() * 0.5 + 0.5);
			star.x = x;
			star.y = y;
			star.graphics.moveTo(radius * Math.cos(72 * Math.PI / 180),radius * Math.sin(72 * Math.PI / 180));
			for(var i:int = 0; i<5; i+=2){
				star.graphics.lineTo(radius * Math.cos((72 * 72 + i) * Math.PI / 180),radius * Math.sin((72 + 72 * i) * Math.PI / 180));
			}
			for(var i:int = 1; i<6; i+=2){
				star.graphics.lineTo(radius * Math.cos((72 * 72 + i) * Math.PI / 180),radius * Math.sin((72 + 72 * i) * Math.PI / 180));
			}
			this._arrayRotation.push(Math.random() >= 0.5 ? (Math.random() * 0.9 + 0.1) * 5 : (Math.random() * -0.9 - 0.1) * 5);
			this._arrayStar.push(star);

			addEventListener(Event.ENTER_FRAME,rotate,false,0,true);
			addChild(star);
		}

		private function rotate(e:Event):void{
			for(var i:int = 0; i < this._arrayStar.length; i++){
				this._arrayStar[i].rotation += this._arrayRotation[i];
			}
		}

	}
}