I’m a graphic designer and trying to create a font using Fontastic_Library. The original version made a font using random function. I would like to draw the shapes using the mouseX and mouseY variables. Can’t figure it out why it doesn’t work.
Someone with knowledge about Fontastic than can tell me how to fix this problem. I think it has something to do with the fact it creates every letter at the same time, and not letter by letter. (can’t find documentation about the way it runs)
import fontastic.*;
Fontastic f;
int version = 0;
//
PVector savedMouse;
//void mousePressed() {
// if (key == ' ') {
// }
//}
void setup() {
size(600, 400);
fill(0);
createFont(); // create the font
savedMouse = new PVector (0, 0);
}
void mousePressed() {
savedMouse.x = mouseX; //Save the mouse position;
savedMouse.y = mouseY;
}
void draw() {
background(255);
PFont myFont = createFont(f.getTTFfilename(), 64); // reading the font that has just been created
textFont(myFont);
textAlign(CENTER, CENTER);
text(Fontastic.alphabet, 0, Fontastic.alphabet.length/2, width/2, height/5);
text(Fontastic.alphabet, Fontastic.alphabet.length/2, Fontastic.alphabet.length, width/2, height/5*2);
text(Fontastic.alphabetLc, 0, Fontastic.alphabet.length/2, width/2, height/5*3);
text(Fontastic.alphabetLc, Fontastic.alphabet.length/2, Fontastic.alphabet.length, width/2, height/5*4);
noLoop();
println("Current saved mouse position: " + savedMouse.x + ", " + savedMouse.y); //Print the saved mouse position
}
void createFont() {
version++;
if (f != null) {
f.cleanup();
}
f = new Fontastic(this, "RandomFont" + nf(version, 4));
f.setAuthor("Andreas Koller");
f.setVersion("1.0");
f.setAdvanceWidth(600);
// go through alphabet and create contours for each glyph
for (char c : Fontastic.alphabet) {
// create a PVector array with 4 random coordinates
PVector[] points = new PVector[4];
//points[0] = new PVector(0, 0); // lower left corner. y coordinates go up in ttf!
//points[1] = new PVector(random(512), 0);
//points[2] = new PVector(random(512), random(1024));
//points[3] = new PVector(0, random(1024));
points[0] = new PVector(mouseX, mouseY);
points[1] = new PVector(mouseX, mouseY);
points[2] = new PVector(mouseX, mouseY);
points[3] = new PVector(mouseX, mouseY);
f.addGlyph(c).addContour(points);
PVector[] pointsLc = new PVector[points.length];
// and to the same for lowercase characters. The contour gets scaled down by 50% in y.
for (int i=0; i<pointsLc.length; i++) {
pointsLc[i] = new PVector();
pointsLc[i].x = points[i].x;
pointsLc[i].y = points[i].y * 0.5;
}
f.addGlyph(Character.toLowerCase(c)).addContour(pointsLc);
}
f.buildFont();
f.cleanup();
}
void keyPressed() {
if (key == ' ') {
createFont();
loop();
}
}