Gradient Coded Colored Ball with Elliptical Movement

by AlejoAsd
♥0 | Line 31 | Modified 2010-01-03 00:03:19 | MIT License
play

ActionScript3 source code

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

package {
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class Bobbing extends Sprite {
			private var angle:Number = 0;
			private var ball:Sprite;
			private var yrange:uint = stage.stageHeight/2-40;
			private var xrange:uint = stage.stageWidth/2-40;

			public function Bobbing() {
			init();
	}
	private function init():void {
			ball = new Sprite();
			var ballcolor:Array = [0xFF4545, 0xFF0000];
			var ballalpha:Array = [1, 1];
			var ballratios:Array = [0, 255];
			ball.graphics.beginGradientFill("radial", ballcolor, ballalpha, ballratios);
			ball.graphics.lineStyle(2);
			ball.graphics.drawCircle(0,0, 40);
			ball.graphics.endFill();
			addChild(ball);
			ball.x = stage.stageWidth / 2;
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
	}
	public function onEnterFrame(event:Event):void {
			ball.y = stage.stageHeight / 2 + Math.cos(angle) * yrange;
			ball.x = stage.stageWidth / 2 + Math.sin(angle) * xrange;
			angle += .1;
		}
	}
}