Monday, May 31, 2010
Font test
int frames;
int[] font = {12044, 13063, 15360, 13059, 15372, 11276, 15620, 3852, 12291,
5888, 3160, 7168, 4032, 3984, 16128, 11788, 16144, 11804,
12676, 8195, 7936, 3168, 3888, 240, 193, 12384, 16224, 832,
13836, 13060, 2828, 14604, 15628, 8257, 16140, 11020, 14607,
255, 15, 12, 96, 4108, 15360, 13056, 80, 160, 4096, 0
};
char[] alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '$', '*', '+', '-', '/', '=', '[', ']',
'(', ')', '_', ' '
};
void setup() {
background(255);
size(600,300);
smooth();
frames = 0;
}
void draw() {
background(255);
drawMessage();
}
void drawMessage() {
char[] word = {'S', 'L', 'U', 'B', ' ', 'L', 'O', 'V', 'E', 'S', ' ', '$', 'Y', 'O', 'U', ' ', '*', '*', ' '};
drawText(word, 600, frames * 3);
++frames;
}
void drawText(char[] word, int sz, int offset) {
strokeWeight(3);
int chars = (sz / 20) + 1;
pushMatrix();
translate(0 - offset % 20, 0);
for (int i = 0; i < chars; ++i) {
int j = int(offset / 20) + i;
drawLetter(word[j % word.length]);
translate(20, 0);
}
popMatrix();
}
void drawLetter(char letter) {
int l = 0;
for (int n = 0; n < alphabet.length; ++n) {
if (alphabet[n] == letter) {
l = font[n];
}
}
for (int i = 0; i < 14; ++i) {
if((l & int(pow(2, 13-i))) != 0) {
switch(i) {
case 0: line(0, 0, 16, 0); break; // t
case 1: line(0, 20, 16, 20); break; // b
case 2: line(0, 0, 0, 10); break; // lt
case 3: line(0, 10, 0, 20); break; // lb
case 4: line(16, 0, 16, 10); break; // rt
case 5: line(16, 10, 16, 20); break; // rb
case 6: line(0, 0, 8, 10); break; // dtl
case 7: line(16, 0, 8, 10); break; // dtr
case 8: line(0, 20, 8, 10); break; // dbl
case 9: line(16, 20, 8, 10); break; // dbr
case 10: line(0, 10, 8, 10); break; // ml
case 11: line(8, 10, 16, 10); break; // mr
case 12: line(8, 0, 8, 10); break; // mt
case 13: line(8, 10, 8, 20); break; // mb
}
}
}
}
int[] font = {12044, 13063, 15360, 13059, 15372, 11276, 15620, 3852, 12291,
5888, 3160, 7168, 4032, 3984, 16128, 11788, 16144, 11804,
12676, 8195, 7936, 3168, 3888, 240, 193, 12384, 16224, 832,
13836, 13060, 2828, 14604, 15628, 8257, 16140, 11020, 14607,
255, 15, 12, 96, 4108, 15360, 13056, 80, 160, 4096, 0
};
char[] alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '$', '*', '+', '-', '/', '=', '[', ']',
'(', ')', '_', ' '
};
void setup() {
background(255);
size(600,300);
smooth();
frames = 0;
}
void draw() {
background(255);
drawMessage();
}
void drawMessage() {
char[] word = {'S', 'L', 'U', 'B', ' ', 'L', 'O', 'V', 'E', 'S', ' ', '$', 'Y', 'O', 'U', ' ', '*', '*', ' '};
drawText(word, 600, frames * 3);
++frames;
}
void drawText(char[] word, int sz, int offset) {
strokeWeight(3);
int chars = (sz / 20) + 1;
pushMatrix();
translate(0 - offset % 20, 0);
for (int i = 0; i < chars; ++i) {
int j = int(offset / 20) + i;
drawLetter(word[j % word.length]);
translate(20, 0);
}
popMatrix();
}
void drawLetter(char letter) {
int l = 0;
for (int n = 0; n < alphabet.length; ++n) {
if (alphabet[n] == letter) {
l = font[n];
}
}
for (int i = 0; i < 14; ++i) {
if((l & int(pow(2, 13-i))) != 0) {
switch(i) {
case 0: line(0, 0, 16, 0); break; // t
case 1: line(0, 20, 16, 20); break; // b
case 2: line(0, 0, 0, 10); break; // lt
case 3: line(0, 10, 0, 20); break; // lb
case 4: line(16, 0, 16, 10); break; // rt
case 5: line(16, 10, 16, 20); break; // rb
case 6: line(0, 0, 8, 10); break; // dtl
case 7: line(16, 0, 8, 10); break; // dtr
case 8: line(0, 20, 8, 10); break; // dbl
case 9: line(16, 20, 8, 10); break; // dbr
case 10: line(0, 10, 8, 10); break; // ml
case 11: line(8, 10, 16, 10); break; // mr
case 12: line(8, 0, 8, 10); break; // mt
case 13: line(8, 10, 8, 20); break; // mb
}
}
}
}
comments

Add a comment: