Shape DotFonts
つづきません。
/**
* Copyright whirlpower ( http://wonderfl.net/user/whirlpower )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4q4k
*/
// つづきません。
package
{
import flash.display.*;
[SWF (backgroundColor = "0x000000", width = "465", height = "465", frameRate = "30")]
public class Main extends Sprite
{
public function Main():void
{
var textArea : ShapeDotFont = new ShapeDotFont( new DotFont().fonts, 200, 100 );
addChild( textArea );
textArea.scaleX = 2;
textArea.scaleY = 2;
textArea.x = 130;
textArea.y = 220;
textArea.color = 0xFFFFFF;
textArea.lineHeight = 16;
textArea.delay = 4;
textArea.ignoreSpace = true;
textArea.add( "TO BE CONTINUED" );
}
}
}
import flash.display.*;
import flash.utils.Dictionary;
import flash.events.*;
internal class ShapeDotFont extends Shape
{
private var fonts :Dictionary;
private var texts :Array = [];
public var margin : int = 1;
public var lineHeight : int = 16;
public var ignoreSpace : Boolean = true;
public var delay : int = 0;
public var color : int = 0xFFFFFF;
private var _width : int;
private var _height : int;
public function ShapeDotFont( fonts:Dictionary, _width:int, _height:int ):void
{
this.fonts = fonts;
this._width = _width;
this._height = _height;
}
public function add( text:String ):void
{
var leng:int = text.length;
for (var i:int = 0; i < leng; i++)
{
var c:String = text.charAt( i );
texts.push( c );
}
texts.push( "return" );
if ( delay <= 0 )
allDraw();
else
addEventListener( Event.ENTER_FRAME, loop );
}
private function allDraw():void
{
var leng:int = texts.length-1;
for ( head; head < leng; head++ )
{
drawFont( texts[ head ] );
}
}
private var count : int = 0;
private var head : int = 0;
private var activeX : int = 0;
private var activeY : int = 0;
private function loop(e:Event):void
{
count++;
if ( count >= delay )
{
count = 0;
do{
var c:String = texts[ head ]
drawFont( c );
head++;
if ( head >= texts.length-1 )
{
removeEventListener( Event.ENTER_FRAME, loop );
return;
}
}
while ( c == " " && ignoreSpace );
}
}
private function drawFont( c:String ):void
{
var font :FontData = fonts[ c ];
if ( !font || font.width == 0 ) font = fonts[ "ng" ];
switch( font.char )
{
case "return":
activeX = 0;
activeY += lineHeight;
return;
case "tab":
activeX = 16;
return;
}
var data : String = font.data;
var width : int = font.width;
var length : int = data.length;
var xx:int = 0, yy:int = 1;
var posX:int, posY:int;
if ( activeX + width > _width )
{
activeX = 0;
activeY += lineHeight;
}
for( var i:int = 0; i < length; i++ )
{
if ( data.charAt(i) == "1" )
{
posX = activeX + xx;
posY = activeY + yy;
graphics.beginFill( color, 1 );
graphics.drawRect( posX, posY, 1, 1 );
graphics.endFill();
}
xx++;
if ( xx >= font.boxWidth )
{
xx = 0;
yy++;
}
}
activeX += width + margin;
}
}
internal class FontData
{
public var char : String;
public var width : int;
public var data : String;
public var boxWidth : int = 0;
public var boxHeight : int = 0;
public var baseline : int = 12;
public function FontData( char:String ):void
{
this.char = char;
}
}
internal class DotFont
{
public var fonts : Dictionary = new Dictionary();
public function DotFont():void
{
fonts[ "A" ] = getFont( "A",7,8,16,12,"000000000011100001101100110001101100011011111110110001101100011000000000000000000000000000000000000000000000000000000000");
fonts[ "B" ] = getFont( "B",7,8,16,12,"000000001111110011000110110001101111110011000110110001101111110000000000000000000000000000000000000000000000000000000000");
fonts[ "C" ] = getFont( "C",7,8,16,12,"000000000011110001100110110000001100000011000000011001100011110000000000000000000000000000000000000000000000000000000000");
fonts[ "D" ] = getFont( "D",7,8,16,12,"000000001111100011001100110001101100011011000110110011001111100000000000000000000000000000000000000000000000000000000000");
fonts[ "E" ] = getFont( "E",7,8,16,12,"000000000111111001100000011000000111110001100000011000000111111000000000000000000000000000000000000000000000000000000000");
fonts[ "F" ] = getFont( "F",7,8,16,12,"000000001111111011000000110000001111110011000000110000001100000000000000000000000000000000000000000000000000000000000000");
fonts[ "G" ] = getFont( "G",7,8,16,12,"000000000011111001100000110000001100111011000110011001100011111000000000000000000000000000000000000000000000000000000000");
fonts[ "H" ] = getFont( "H",7,8,16,12,"000000001100011011000110110001101111111011000110110001101100011000000000000000000000000000000000000000000000000000000000");
fonts[ "I" ] = getFont( "I",7,8,16,12,"000000000111111000011000000110000001100000011000000110000111111000000000000000000000000000000000000000000000000000000000");
fonts[ "J" ] = getFont( "J",7,8,16,12,"000000000000011000000110000001100000011000000110110001100111110000000000000000000000000000000000000000000000000000000000");
fonts[ "K" ] = getFont( "K",7,8,16,12,"000000001100011011001100110110001111000011111000110111001100111000000000000000000000000000000000000000000000000000000000");
fonts[ "L" ] = getFont( "L",7,8,16,12,"000000000110000001100000011000000110000001100000011000000111111000000000000000000000000000000000000000000000000000000000");
fonts[ "M" ] = getFont( "M",7,8,16,12,"000000001100011011101110111111101111111011010110110001101100011000000000000000000000000000000000000000000000000000000000");
fonts[ "N" ] = getFont( "N",7,8,16,12,"000000001100011011100110111101101111111011011110110011101100011000000000000000000000000000000000000000000000000000000000");
fonts[ "O" ] = getFont( "O",7,8,16,12,"000000000111110011000110110001101100011011000110110001100111110000000000000000000000000000000000000000000000000000000000");
fonts[ "P" ] = getFont( "P",7,8,16,12,"000000001111110011000110110001101100011011111100110000001100000000000000000000000000000000000000000000000000000000000000");
fonts[ "Q" ] = getFont( "Q",7,8,16,12,"000000000111110011000110110001101100011011011110110011000111101000000000000000000000000000000000000000000000000000000000");
fonts[ "R" ] = getFont( "R",7,8,16,12,"000000001111110011000110110001101100111011111000110111001100111000000000000000000000000000000000000000000000000000000000");
fonts[ "S" ] = getFont( "S",7,8,16,12,"000000000111100011001100110000000111110000000110110001100111110000000000000000000000000000000000000000000000000000000000");
fonts[ "T" ] = getFont( "T",7,8,16,12,"000000000111111000011000000110000001100000011000000110000001100000000000000000000000000000000000000000000000000000000000");
fonts[ "U" ] = getFont( "U",7,8,16,12,"000000001100011011000110110001101100011011000110110001100111110000000000000000000000000000000000000000000000000000000000");
fonts[ "V" ] = getFont( "V",7,8,16,12,"000000001100011011000110110001101110111001111100001110000001000000000000000000000000000000000000000000000000000000000000");
fonts[ "W" ] = getFont( "W",7,8,16,12,"000000001100011011000110110101101111111011111110111011101100011000000000000000000000000000000000000000000000000000000000");
fonts[ "X" ] = getFont( "X",7,8,16,12,"000000001100011011101110011111000011100001111100111011101100011000000000000000000000000000000000000000000000000000000000");
fonts[ "Y" ] = getFont( "Y",7,8,16,12,"000000000110011001100110011001100011110000011000000110000001100000000000000000000000000000000000000000000000000000000000");
fonts[ "Z" ] = getFont( "Z",7,8,16,12,"000000001111111000001110000111000011100001110000111000001111111000000000000000000000000000000000000000000000000000000000");
fonts[ " " ] = getFont( " ",5,8,16,12,"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
fonts[ "0" ] = getFont( "0",7,8,16,12,"000000000011100001001100110001101100011011000110011001000011100000000000000000000000000000000000000000000000000000000000");
fonts[ "1" ] = getFont( "1",7,8,16,12,"000000000001100000111000000110000001100000011000000110000111111000000000000000000000000000000000000000000000000000000000");
fonts[ "2" ] = getFont( "2",7,8,16,12,"000000000111110011000110000011100011110001111000111000001111111000000000000000000000000000000000000000000000000000000000");
fonts[ "3" ] = getFont( "3",7,8,16,12,"000000000111111000001100000110000011110000000110110001100111110000000000000000000000000000000000000000000000000000000000");
fonts[ "4" ] = getFont( "4",7,8,16,12,"000000000001110000111100011011001100110011111110000011000000110000000000000000000000000000000000000000000000000000000000");
fonts[ "5" ] = getFont( "5",7,8,16,12,"000000001111110011000000111111000000011000000110110001100111110000000000000000000000000000000000000000000000000000000000");
fonts[ "6" ] = getFont( "6",7,8,16,12,"000000000011110001100000110000001111110011000110110001100111110000000000000000000000000000000000000000000000000000000000");
fonts[ "7" ] = getFont( "7",7,8,16,12,"000000001111111011000110000011000001100000110000001100000011000000000000000000000000000000000000000000000000000000000000");
fonts[ "8" ] = getFont( "8",7,8,16,12,"000000000111100011000100111001000111100010011110100001100111110000000000000000000000000000000000000000000000000000000000");
fonts[ "9" ] = getFont( "9",7,8,16,12,"000000000111110011000110110001100111111000000110000011000111100000000000000000000000000000000000000000000000000000000000");
fonts[ "ng" ] = getFont( "ng",7,8,16,12,"000000001111111011000110101010101001001010101010110001101111111000000000000000000000000000000000000000000000000000000000");
fonts[ "return" ] = new FontData( "return" );
}
private function getFont( c:String, width:int, boxWidth:int, boxHeight:int, baseline:int, data:String ):FontData
{
var font :FontData = new FontData( c );
font.width = width;
font.boxWidth = boxWidth;
font.boxHeight = boxHeight;
font.baseline = baseline;
font.data = data;
return font;
}
}