Pie Draw

A small javascript fx I rushed in a hurry. This is for the DBF javascript competition 2007.
Surprisingly, I won this competition with this entry (yeah ;-)).

Technique

This is coded in pure JavaScript using my own engine, the JavaScript FrameBuffer GraphicsLibrary.

Source

/**
 *  PieDraw
 *  
 *  A small javascript fx rushed in a hurry for 
 *  the dbf javascript competition in 2007.
 * 
 *  @author benny!weltenkonstrukteur.de
 * 
 */	 

var x_res		= 50;
var y_res		= 50;
var pixel_width = 2;
var pixel_height= 2;
jsfbgl_framerate= 10;
jsfbgl_buffer 	= new Array(x_res * y_res);

jsfbgl_open(x_res, y_res, pixel_width, pixel_height);
		
var radius = 16;
var circleRadius = 24;
var circleCenter_X = 25;
var circleCenter_Y = 25;
var state  = 0;
PieDraw();


// *** Functions ************************************************
	 
function PieDraw() {
	if ( state == 0 ) {
		circleRadius--;
		if ( circleRadius == 1 ) {
			state = 1;
		}
	} else if ( state == 1 ) {
		circleRadius++;
		if ( circleRadius == 24 ) {
			state = 0;
		}				
	}
	radius = radius - 2 % 360;
	if ( radius == -360 ) {
		radius = 0;
	}
	
	x = Math.floor ( circleRadius * Math.cos( radius * ( 2 * Math.PI / 360)) + circleCenter_X );
	y = Math.floor ( circleRadius * Math.sin( radius * ( 2 * Math.PI / 360)) + circleCenter_Y );
	var red 	= Math.floor(200*Math.random())+50;
	var green	= Math.floor(200*Math.random())+50;
	var blue	= Math.floor(200*Math.random())+50;
			
	var hRed	= NumToHexString(red);
	var hGreen	= NumToHexString(green);
	var hBlue	= NumToHexString(blue);
			
	var color	= hRed + hGreen + hBlue;
						
	jsfbgl_plot( x, y, color );			
	window.setTimeout('PieDraw()', jsfbgl_framerate);	
}
		
function NumToHexString(hexnumber) {
// takes a number as sole argument, returns the hex value. Will make
// the return value at leats two places long by adding zeroes.
// I.e., NumToHexString(10)=="0a".
   var hexstring="";
   var hexchar;
   var hexones;
   var i=0;
		
   hexnumber=Math.floor(hexnumber);
   while (hexnumber != 0) {
       i++;
       hexones=hexnumber % 16;
       hexnumber -= hexones;
       hexnumber /= 16;
		
      if (hexones>9) {
	  if (hexones==10) hexchar="a";
	  if (hexones==11) hexchar="b";
	  if (hexones==12) hexchar="c";
	  if (hexones==13) hexchar="d";
	  if (hexones==14) hexchar="e";
	  if (hexones==15) hexchar="f";
      }
      else hexchar=hexones;
		
      hexstring = hexchar + hexstring;
   }
		
   for (;i<2;i++) {
      hexstring="0"+hexstring;
   }
		
   return hexstring;
}