Font List

Hi There

I am using the next code to have a Font List. It works perfectly. But i want to replace the ''random(0, 2)" by the sequence of the font list. So, i want that the font is not anymore random. Do someone know how i can fix this?

Greetings

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); }

Tagged:

Answers

  • float x=1;

    Or

    int x=1;

  • Sequence for loop ( See Reference)

  • Thanks, but to be more specific, i want in the font sequence that each font (e) is 200 pixels to the bottom.

    for (int e = 0; e < maxFont; e++) {    
      float x = 1;
      int y = int(x);
      textFont(font[y], 32);     
      fill(0);
      text("Font", width-75, e*200, 200, 100);
    }
    
  • you're using

    afont = createFont("FreeMono", 1);
    bfont = createFont("Kinnari-Italic", 1);
    cfont = createFont("Norasi", 1);
    

    which you can't loop over. you really want an array of PFont.

  • String[] fontList ;
    
    void setup() {
      size(1200, 900);
      fontList = PFont.list();  // Strings
      // printArray(fontList);
      noLoop();
    }
    
    
    
    void draw() {
      for (int e = 0; e < fontList.length; e++) {    
        // float x = 1;
        // int y = int(x);
        PFont temp = createFont(fontList[e], 32); // PFont
        textFont(temp, 32);     
        fill(0);
        text("Font "+trim(fontList[e]), 75, e*200, 200, 100);
        if (e*200>height+90) {
          println("break");
          break;
        }
      }
    }
    
  • you are welcome!

    ;-)

  • general it is not good to use createFont outside setup - I just did that here because I use noLoop() anyway

    alternatively, have a 2nd array of the fonts (PFont[] fontListOfPFont;) and set it up in setup() and use it in draw()

  • Can you suggest me how i can connect this with an array font list that i set in a local folder

  • what is this

    array font list that i set in a local folder

    ?

    do you mean the fonts you have in the folder (ttf / vlw files) or a text file with a list in it?

  • i want to make an array font list with selected fonts. The question is how i can connect it with an arrray list like below

    afont = createFont("FreeMono", 1); bfont = createFont("Kinnari-Italic", 1); cfont = createFont("Norasi", 1);

  • edited May 2016

    replace line 1 with

    String[] fontList = {"FreeMono",
    "Kinnari-Italic",
    "Norasi"};
    

    then like above but without the line 5

Sign In or Register to comment.