We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello! At the moment i am loading fonts into my work by using the PFont mode. This is the code i am using:
PFont font;
PFont.list();
String[] fontList = PFont.list();
println(fontList);
font = createFont("Akkurat-Mono.ttf", 45);
textFont(font);
fill(0);
I was curious if i could load more than one font, for example five. And than display a text which uses this randomfont function, to display the text in a variety of fonts. I don't know exactly how to do this, has anyone an idea?
Merci beaucoup!
Sander
Answers
here
This loads a random font on each frame and uses it for display. You could do the same thing and load a PFont array in setup()...
Hope that helps.
edit: too slow :(
I am sorry ;-)
The random font seems to work! So i'm one step closer, thanks :) However, it still displays the entire text in the same font. I tried something with the charAt() function, but then i still got the same. And i thought, in order to use just 5 fonts instead of my entire collection, could i loop trought the fonts i have in the data folder instead of my whole computer? Thanks for your helpful feedback, it really means a lot to me!
well... this is totally different from what you wanted first. Why did you ask the wrong thing first?
here is a version that changes the font for each letter
the other things should be easy too but I don't know it (or have time)
Im sorry i didn't formulated it correct, thanks!
it just occurred to me...
Hi, I'm really interested to get this to work but I just started learning Processing/Java a week ago. The examples with PFont.list works just fine but I can't seem to get the other to function. I receive a "ArrayIndexOutOfBoundsException: 0" on the line "font = fonts[randomIndex];". I have placed some .ttf fonts in my /data folder and I can see that thous are printed in the console.
Would really appreciate some help! Torbjörn
you are referring to that?
pls show your entire code
randomIndex must be defined correctly ---
int randomIndex = int(random(fontList.length));
This was the code I was referring to. I get an error saying
StringList size=0 [ ]
and theprintln(inventory);
doesn't print to the console.Also. Can't seem to figure out how to formate the code-block correctly with every line starting with a number?
Weird... now the code looks right!
several issues here
1.
the sketch checks only the fonts in the data directory of the sketch
you need to have fonts therein
use in the IDE menu tools|create font
2.
the created fonts are vlw but the sketch accepted only ttf - I changed that now
;-)
quote
probably you need 2 empty lines before and after the code
Thank you for the fast reply, really appreciate your help! I have .ttf fonts in my /data folder but those doesn't seem to be loaded into StringList as it returns size = 0. When I added some .vlw font they where added to StringList but they don't display when I run the code...
yeah...
it's this:
listFiles[i].indexOf(".TTF")>0
maybe your fonts are named ttf instead of TTF
make it
AH! That was it! Thank you very much :D
;-)
btw.
just a remark
quote
it's not an error though.
StringList size=0 [ ] is just what
println(inventory);
gives out sinceinventory
was empty (soprintln(inventory);
did print to the console but not what you've expected);-)