Rainbow Percents thanks to ryan taylor //http://www.boostworthy.com/blog/?p=200

by alidrongo
♥2 | Line 45 | Modified 2009-11-22 02:10:12 | MIT License
play

ActionScript3 source code

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

package {
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	public class rainbow extends Sprite
	{
		private var theX:int = 0;
		private var counter:int = 0;
		private var total:int = 100;
		private var tim:Timer;
		
		public function rainbow()
		{
			init();
		}
		
		function  drawL(t:TimerEvent):void
		{
			//thanks to ryan taylor 
			//http://www.boostworthy.com/blog/?p=200
			var nColorPercent:Number = counter/total;
			
			// Calculate the radians of the angle to use for rotating color values.
			var nRadians:Number = (-360 * nColorPercent) * (Math.PI / 180);
			
			// Calculate the RGB channels based on the angle.
			var nR:Number = Math.cos(nRadians)                   * 127 + 128 << 16;
			var nG:Number = Math.cos(nRadians + 2 * Math.PI / 3) * 127 + 128 << 8;
			var nB:Number = Math.cos(nRadians + 4 * Math.PI / 3) * 127 + 128;
			
			// OR the individual color channels together.
			var nColor:Number  = nR | nG | nB;
			
			var color = nRadians;
			var myS:Sprite = new Sprite();
			myS.x =  counter*5;
			myS.graphics.lineStyle(5, nColor);
			myS.graphics.lineTo(0,1000);
			addChild(myS);
			counter ++
			
		}
			
		
		private function timComp(t:TimerEvent):void
		{
			counter = 0;			
			tim.removeEventListener(TimerEvent.TIMER_COMPLETE, timComp);
                        tim. removeEventListener(TimerEvent.TIMER, drawL);
			
		}
		private function init():void
		{
			tim = new Timer(20, 100);
			tim.addEventListener(TimerEvent.TIMER, drawL);
			tim.addEventListener(TimerEvent.TIMER_COMPLETE, timComp);
			tim.start();
		}
	
	}
}