/**
* @date 21/11/2008
* @author borealkiss
* @link http://blog.boreal-kiss.com/
*/packagecom.borealkiss.controls{importflash.display.DisplayObjectContainer;
importflash.errors.IllegalOperationError;
/**
* Abstract class
*/publicclassViewController{protectedvar_target:DisplayObjectContainer;
/**
* Constructor
*/publicfunctionViewController(target:DisplayObjectContainer){_target=target;
if(Object(this)==ViewController){thrownewIllegalOperationError("Abstract class must be inherited in a subclass");
}}publicfunctiondraw():void{//Must be overridden in a subclass.
}}}
/**
* @date 23/11/2008
* @author borealkiss
* @link http://blog.boreal-kiss.com/
*/packagecom.borealkiss.display{importflash.display.Sprite;
importflash.display.Graphics;
importflash.display.BitmapData;
importcom.borealkiss.display.FontBitmapData;
publicclassHairyFontextendsSprite{protectedvar_sourceBitmapData:FontBitmapData;
protectedvar_random:uint;
protectedvar_stroke:uint;
protectedvar_limit:uint;
protectedconstALPHA:Number= 0.1;
/**
* Constructor
*/publicfunctionHairyFont(sourceBitmapData:FontBitmapData,
limit:uint,random:uint,stroke:uint=0x0){_sourceBitmapData=sourceBitmapData;
_limit=limit;
_random=random;
_stroke=stroke;
this.init();
}protectedfunctioninit():void{this.update();
}protectedfunctionupdate():void{varrectWidth:int=_sourceBitmapData.width;
varrectHeight:int=_sourceBitmapData.height;
varg:Graphics=this.graphics;
g.clear();
g.lineStyle(0,_stroke,ALPHA);
for(vari:int=0; i<_limit; i++){varx:int=int(Math.random()*rectWidth);
vary:int=int(Math.random()*rectHeight);
varcolor32:uint=_sourceBitmapData.getPixel32(x,y);
if(isInFont(color32)){//Start point
varstartX:Number=x;
varstartY:Number=y;
//Anchor point so that the hair goes outer.
varhairRad:Number=_random*Math.random();
varhairTheta:Number=Math.random()*2*Math.PI;
varanchorX:Number=startX+hairRad*Math.cos(hairTheta);
varanchorY:Number=startY+hairRad*Math.sin(hairTheta);
//Control point for the Bezier curve.
varcontrolRad:Number=_random*Math.random();
varcontrolTheta:Number=Math.random()*2*Math.PI;
varcontrolX:Number=startX+controlRad*Math.cos(controlTheta);
varcontrolY:Number=startY+controlRad*Math.sin(controlTheta);
g.moveTo(startX,startY);
g.curveTo(controlX,controlY,anchorX,anchorY);
}}}/**
* Check the pixel color.
*
* @param color32 Pixel value in a bitmap data including the alpha channel.
* @return true if the pixel color is the same as that of the font color, otherwise false.
*/protectedfunctionisInFont(color32:uint):Boolean{varcolor24:uint=color32& 0xFFFFFF;
if(color24==_sourceBitmapData.fontColor){returntrue;
}returnfalse;
}/**
* @return A random value between -random and random.
*/protectedfunctionrandomGen(random:uint):Number{return 2*random*(Math.random()- 1/2);
}}}