Text
Even in the pixel-world it is crucial to have a feature of displaying text information and numbers.
I've drawn a pixelart font. Each glyph should be placed in a 6x8 pixels cell. The font contains Upper and Lower english letters, special characters, big cyrilic letters and digits. Font may be extended later.
Here is the full image:
I want to make something special and this font would not
be monospace! The blue column would contain binary data. There are 8 bits of binary data in the last column.
Every glyph
is extended with the metadata that contains width
, height
, deltaX
, deltaY
.
First 4 bits would encode deltaY. First 3 bits encode a number from 0-7, and the last bit is for positive (0) and negative (1) movement.
Next 4 bits are encoding deltaX in the same way.
deltaX
anddeltaY
helps to position the glyph. For example, it makes possible to moveg
,y
letters a bit down
The next column is used for encode width
and height
of the glyph
.
Also, I've made a fallback for the unknown character
/*
Arguments of the print function:
text
x
y
color
scaleX = 1
scaleY = 1
*/
print( 'THE QUICK BROWN FOX JUMPS OVER THE \nLAZY DOG ppp прполдекнегшщш', 10, 10, colors[ 1 ] );
\n
is supported as a new line character
var textColor = 0x807322, y = 0;
print( 'Abc, def. Ghi ?!:.,;', 10, y+=15, textColor );
print( 'The quick brown fox jumps over the lazy dog', 10, y+=15, textColor );
// \n is here and a lot of unknown characters!
print( 'THE QUICK BROWN FOX JUMPS OVER THE \nLAZY DOG ppp прполдекнегшщш',
10, y+=15, textColor );
print( 'GAME OVER ЖЯЖ«Я', 50, y+=30, textColor, 2, 2 );
print( 'iiiiiiiiii,,::', 10, y+=25, textColor );
print( 'oooooooooo', 10, y+=15, textColor );
print( 'mmmmmmmmmm', 10, y+=15, textColor );
Maybe later I would add some functions for text alignment. For now there are not.
added
getPrintWidth
method that takestext
as input and returns aNumber
. If you need scaling — you should do it manually by using themultiplication
!