We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Array Fonts
Page Index Toggle Pages: 1
Array Fonts (Read 670 times)
Array Fonts
May 17th, 2010, 1:09pm
 
Hallo people,

i want to create some fonts and use it by random.

but i cant see through.
PLZ HELP!

Code:
PFont afont, bfont, cfont;

String[]mainfont = {"afont", "bfont", "cfont"};

void setup() {
 size(200,200);
 
 afont = createFont("FreeMono", 1);
 bfont = createFont("Kinnari-Italic", 1);
 cfont = createFont("Norasi", 1);

}

void draw(){
 
 float x = random(0,2);
 int y = int (x);
 
 textFont(mainfont[y]);

// GET THE MESSAGE: method textFont(PFont) in the type PApplet is // not applicable for the arguments (String)

 text("I want to get here everytime another FONTtype", 50, 50);
 }
Re: Array Fonts
Reply #1 - May 17th, 2010, 2:22pm
 
You cannot call a variable by its name (well, you can, but it is beyond your basic need).
What you want is an array of fonts, not an array of variable names:
Code:
PFont[] fontList = new PFont[3];

void setup() {
 size(200, 200);
 
 fontList[0] = createFont("FreeMono", 1);
 fontList[1] = createFont("Kinnari-Italic", 1);
 fontList[2] = createFont("Norasi", 1);
}

void draw() {
 background(255);
 float x = random(0, 2);
 int y = int(x);
 
 textFont(fontList[y], 12);
 text("I want to get here everytime another FONTtype", 50, 50);
}
Re: Array Fonts
Reply #2 - May 17th, 2010, 2:52pm
 
Great!

Thank you for the fast HELP!

Greetings :]
Page Index Toggle Pages: 1