Pov Font Creator for Arduino projects
in
Integration and Hardware
•
1 year ago
I've had a go at putting together a P.O.V (persistence of vision) font creator to create fonts for an Arduino project i'm working on.
If you're not sure what P.O.V. is (I didn't know until two days ago), its basically a way of creating the illusion of a two dimensional image, perhaps of LED's for example, by using a single row of LED's moving rapidly - think, LEDs on a fan spinning round creating the illusion of lettering or images.
This code is for text 16 'pixels' high. Before using, a 16pt Arial Bold font in the data directory needs to be created - make sure smoothing is off when you create the font. You could use different fonts but I haven't tested it.
This code makes arrays of 16bit numbers that can be processed in Arduino etc to switch LED's on or off. But it can also save to file strings of the binary data
Just comment out the parts you don't want in your file.
e.g. The letter A
created in binary:
0001000000000000
0001111000000000
0000111111000000
0000001111110000
0000001101111110
0000001100001110
0000001100001110
0000001101111110
0000001111110000
0000111111000000
0001111000000000
0001000000000000
and as 16bit numbers:
'A' = {4096, 7680, 4032, 1008, 894, 782, 782, 894, 1008, 4032, 7680, 4096 };
The file created makes all ascii characters from 40 -127.
Heres the code (you need to create the font .vlw file first) :
PFont font;
PrintWriter output;
PImage canvas;
int ascii = 32;
String letter = " ";
String[] pov;
int[] povnums;
void setup(){
size(300,300);
font = loadFont("font.vlw");
output = createWriter("povarrays.txt");
textFont(font);
fill(0);
}
void draw(){
if (ascii < 128){
letter = (char(ascii)+"");
background(255);
fill(0);
text(letter,20,20);
drawbig();
ascii++;
}
else
{
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}
}
void drawbig(){
int letterheight = 16;
int letterwidth = int(textWidth(letter));
String[] pov = new String[letterwidth];
int[] povnums = new int[letterwidth];
for (int i = 0; i<letterwidth; i++){
String povline = ""; //line of 0s and 1s
for (int j = 0; j<letterheight; j++){
color pixelcol=get(20+i,22-j); //you may need to change the 22 as the font dips below the base line for descenders
if (int(brightness(pixelcol)) > 150){
povline = povline+"0";
}
else{
povline = povline+"1";
}
fill(pixelcol);
rect (20+(i*10),280-(j*10),10,10);
}
pov[i] = povline;
povnums[i] = unbinary(povline);
}
for (int i = 0; i<pov.length; i++){output.println(pov[i]);}; // prints binary display
output.println();
output.print("'"+letter+"' = {"); //the next bit prints the number array
output.print(povnums[0]);
for (int i = 1; i<pov.length; i++){output.print(", "+povnums[i]);};
output.print(" };");
output.println();
output.println();
}
If you're not sure what P.O.V. is (I didn't know until two days ago), its basically a way of creating the illusion of a two dimensional image, perhaps of LED's for example, by using a single row of LED's moving rapidly - think, LEDs on a fan spinning round creating the illusion of lettering or images.
This code is for text 16 'pixels' high. Before using, a 16pt Arial Bold font in the data directory needs to be created - make sure smoothing is off when you create the font. You could use different fonts but I haven't tested it.
This code makes arrays of 16bit numbers that can be processed in Arduino etc to switch LED's on or off. But it can also save to file strings of the binary data
Just comment out the parts you don't want in your file.
e.g. The letter A
created in binary:
0001000000000000
0001111000000000
0000111111000000
0000001111110000
0000001101111110
0000001100001110
0000001100001110
0000001101111110
0000001111110000
0000111111000000
0001111000000000
0001000000000000
and as 16bit numbers:
'A' = {4096, 7680, 4032, 1008, 894, 782, 782, 894, 1008, 4032, 7680, 4096 };
The file created makes all ascii characters from 40 -127.
Heres the code (you need to create the font .vlw file first) :
PFont font;
PrintWriter output;
PImage canvas;
int ascii = 32;
String letter = " ";
String[] pov;
int[] povnums;
void setup(){
size(300,300);
font = loadFont("font.vlw");
output = createWriter("povarrays.txt");
textFont(font);
fill(0);
}
void draw(){
if (ascii < 128){
letter = (char(ascii)+"");
background(255);
fill(0);
text(letter,20,20);
drawbig();
ascii++;
}
else
{
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}
}
void drawbig(){
int letterheight = 16;
int letterwidth = int(textWidth(letter));
String[] pov = new String[letterwidth];
int[] povnums = new int[letterwidth];
for (int i = 0; i<letterwidth; i++){
String povline = ""; //line of 0s and 1s
for (int j = 0; j<letterheight; j++){
color pixelcol=get(20+i,22-j); //you may need to change the 22 as the font dips below the base line for descenders
if (int(brightness(pixelcol)) > 150){
povline = povline+"0";
}
else{
povline = povline+"1";
}
fill(pixelcol);
rect (20+(i*10),280-(j*10),10,10);
}
pov[i] = povline;
povnums[i] = unbinary(povline);
}
for (int i = 0; i<pov.length; i++){output.println(pov[i]);}; // prints binary display
output.println();
output.print("'"+letter+"' = {"); //the next bit prints the number array
output.print(povnums[0]);
for (int i = 1; i<pov.length; i++){output.print(", "+povnums[i]);};
output.print(" };");
output.println();
output.println();
}