Archive for October 13th, 2008
A graphical text class.
This is a class that didn’t quite make the cut into something I’m working on – so I’ve put it on my blog. I’m sure someone else will enjoy it. It’s a graphical writing class that utilises the graphics api to draw simple letter shapes like this…
![]()
For example, to produce the above result, call it with the following parameters…
new Write(this,16,128,’abcdefghijklmnopqrstuvwxyz’,3);
new Write(this,16,150,’abcdefghijklmnopqrstuvwxyz’);
Enjoy.
package asfiles {
import flash.display.Sprite;
public class Write extends Sprite {
protected static const alphabet:Array=[
[[0,4, 0,2, 2,0, 4,2, 4,4],[0,2, 4,2]],
[[0,0, 3,0, 4,1, 4,2, 0,2, 3,2, 4,3, 4,4, 0,4, 0,0]],
[[4,0, 1,0, 0,1, 0,3, 1,4, 4,4]],
[[0,0, 3,0, 4,1, 4,3, 3,4, 0,4, 0,0]],
[[4,0, 0,0, 0,4, 4,4],[0,2, 3,2]],
[[4,0, 0,0, 0,4],[0,2, 3,2]],
[[4,0, 1,0, 0,1, 0,3, 1,4, 4,4, 4,2, 2,2]],
[[0,0, 0,4],[4,0, 4,4],[0,2, 4,2]],
[[2,0, 2,4],[1,0, 3,0],[1,4, 3,4]],
[[3,0, 3,3, 2,4, 1,4, 0,3],[2,0, 4,0]],
[[0,0, 0,4],[4,0, 0,2, 4,4]],
[[0,0, 0,4, 4,4]],
[[0,4, 0,0, 2,2, 4,0, 4,4]],
[[0,4, 0,0, 4,4, 4,0]],
[[1,0, 3,0, 4,1, 4,3, 3,4, 1,4, 0,3, 0,1, 1,0]],
[[0,4, 0,0, 4,0, 4,2, 0,2]],
[[1,0, 3,0, 4,1, 4,3, 3,4, 1,4, 0,3, 0,1, 1,0],[3,3, 5,5]],
[[0,4, 0,0, 4,0, 4,2, 0,2],[2,2, 4,4]],
[[4,0, 1,0, 0,1, 0,2, 4,2, 4,3, 3,4, 0,4]],
[[0,0, 4,0],[2,0, 2,4]],
[[0,0, 0,3, 1,4, 3,4, 4,3, 4,0]],
[[0,0, 0,2, 2,4, 4,2, 4,0]],
[[0,0, 0,4, 2,2, 4,4, 4,0]],
[[0,0, 4,4],[0,4, 4,0]],
[[0,0, 2,2, 4,0],[2,2, 2,4]],
[[0,0, 4,0, 0,4, 4,4],[1,2, 3,2]]
]
private static const kscale:Number=1.4;
private static const kcolour:uint=0x999999;
private const lettergap:int=6;
public function Write(screen:Sprite,xx:int,yy:int,txt:String,scale:Number=kscale,colour:uint=kcolour) {
screen.addChild(this);x=xx;y=yy;
graphics.clear();
graphics.lineStyle(1,colour);
write(txt,scale);
}
private function write(txt:String,scale:Number):void {
var pos:int=0;
var letter:Array;
txt=txt.toLowerCase();
for (var i:int=0;i<txt.length;i++) if (txt.substr(i,1)!=' ') {
letter=alphabet[txt.charCodeAt(i)-'a'.charCodeAt(0)];
for (var j:int=0;j<letter.length;j++) {
graphics.moveTo(pos+letter[j][0]*scale,letter[j][1]*scale);
for (var k:int=2;k<letter[j].length;k+=2) {
graphics.lineTo(pos+letter[j][k]*scale,letter[j][k+1]*scale);
}
}
pos+=lettergap*scale;
} else pos+=lettergap*scale;
}
}
}
Add comment October 13, 2008
