program Sample;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
TextCanvas in 'TextCanvas.pas',
DigitFont in 'DigitFont.pas';
var
DigitFont : TDigitFont;
begin
DigitFont := TDigitFont.Create;
try
DigitFont.FontSize := 1;
DigitFont.WriteDigit('01234');
WriteLn;
DigitFont.FontSize := 2;
DigitFont.WriteDigit('56789');
finally
DigitFont.Free;
end;
Write('Press any key...');
ReadLn;
end.
procedure TDigitFont.WriteDigit(Digit:string);
const
_FontWidth = 3;
_FontHeight = 5;
var
sFontData : string;
Loop: Integer;
begin
FCanvas.Width := Length(Digit) * (FontSize + 1) * _FontWidth;
FCanvas.Height := FontSize * _FontHeight;
FCanvas.Clear;
for Loop := 0 to Length(Digit)-1 do begin
// 현재 폰트를 찍을 위치로
FCanvas.MoveTo(Loop * (FontSize + 1) * _FontWidth, 0);
// 현재 폰트의 벡터 정보 가져오기
sFontData := _DigitFontData[Ord(Digit[Loop+1]) - Ord('0')];
draw_Digit(sFontData);
end;
FCanvas.Draw;
end;
procedure TDigitFont.draw_Digit(FontData: string);
var
Loop : Integer;
begin
for Loop := 1 to Length(FontData) do begin
case FontData[Loop] of
'l': FCanvas.MoveLeft;
'r': FCanvas.MoveRight;
'd': FCanvas.MoveDown;
'u': FCanvas.MoveUp;
'<': FCanvas.MoveLeft(FontSize);
'>': FCanvas.MoveRight(FontSize);
'.': FCanvas.MoveDown(FontSize);
'^': FCanvas.MoveUp(FontSize);
'L': FCanvas.LineLeft(FontSize);
'R': FCanvas.LineRight(FontSize);
'D': FCanvas.LineDown(FontSize);
'U': FCanvas.LineUp(FontSize);
end;
end;
end;
type
const
_DigitFontData : array [0..9] of string = (
'dDdDrRuUuUlL', // 0
'rrdDdD', // 1
'rRdDlLdDrR', // 2
'rRdDdDlL^urR', // 3
'dDrR^DdD', // 4
'rR<ldDrRdDlL', // 5
'rLdDrRdDlLuU', // 6
'rRdDdD', // 7
'rRdDlLdDrRuUl<uU', // 8
'd.rLuUrRdDdDlL' // 9
);
lrdu : 한 칸 이동 (각각 Left, Right, Down, Up)
<>,^ : 폰트 크기 만큼 이동 (각각 Left, Right, Down, Up)
LRDU : 폰트 크기 만큼 직선 그리기 (각각 Left, Right, Down, Up)
type
TTextCanvas = class
private
public
procedure Clear;
procedure MoveTo(X,Y:integer);
procedure MoveLeft(Count:integer = 1);
procedure MoveRight(Count:integer = 1);
procedure MoveDown(Count:integer = 1);
procedure MoveUp(Count:integer = 1);
procedure LineLeft(Count:integer = 1);
procedure LineRight(Count:integer = 1);
procedure LineDown(Count:integer = 1);
procedure LineUp(Count:integer = 1);
procedure Draw;
property X : integer;
property Y : integer;
property Width : integer;
property Height : integer;
end;
| Tron 게임 (0) | 2012.02.17 |
|---|---|
| 퍼포먼스를 위한 발악 (2) | 2012.02.11 |
| 아들 넘의 첫 번 째 게임 - 홀짝 맞추기 (0) | 2012.01.17 |
| 유치원생을 위한 프로그래밍 세 번 째 날 (0) | 2011.12.26 |
| 유치원생 아들에게 프로그래밍 가르치기 (4) | 2011.12.24 |