Processing > Texte

1.  Afficher du texte

text("bonjour",x,y);

2.  Fonctions d'affichage du texte

3.  Caractères spéciaux

Retour à la ligne\n
Tabulation\t
Apostrophe\'
Guillemets\"
Barre oblique inverse\\

4.  Les polices

  1. Créez la police (à partir du menu Tools -> Create Font) et nommez la "police.vlw"
  2. Déclarez un PFont: PFont police;
  3. Chargez la police: police = loadFont("police.vlw");
  4. Sélectionnez le PFont et spécifiez sa taille: textFont(police,12);
  5. Affichez le texte en spécifiant sa position: text("bonjour la police",10,10);
// Creez la police (a partir du menu ''Tools -> Create Font'') et nommez la "police.vlw"

PFont police;
int taille;

void setup() {
        [...]
        police = loadFont("police.vlw");
        taille = 12;
        textFont(police,taille);
        [...]
}

void draw() {
        [...]
        text("bonjour",x,y);
        [...]
}

5.  Les chaînes de caractères:

5.1  Création d'un String:

String a = "WXYZ";
char caracteres[] = {'W', 'X', 'Y', 'Z'};
String b = new String(caracteres);
String c = new String(caracteres,2,2);

5.2  Quelques méthodes des String:

String a = "WXYZ";
a.charAt(index)
a.length()
a.equals(String)
String b = a.toUpperCase()
String c = a + b //concaténation

6.  Tableau de String

String [] mots;

int index;

void setup() {
        size(400,400);
        smooth();

        mots = new String[3];

        mots[0] = "how";
        mots[1] = "are";
        mots[2] = "you?";


}

void draw () {
        background(0);

        textAlign(CENTER);
        textSize(32);

        fill(255);
        text(mots[index],width/2,height/2);

}

void mousePressed() {
        index = index + 1;
        if ( index > 2 ) index = 0;

}

7.  Encadrer le texte


String monmot = "time elapsed: ";

void setup() {
        size(400,400);
        smooth();
}

void draw () {
        background(0);

        textAlign(CENTER,CENTER);
        textSize(32);


        float w = textWidth(monmot+" "+millis());
        rectMode(CENTER);
        fill(125);
        rect(width/2,height/2,w+20,100);
        fill(255);
        text(monmot+" "+millis(),width/2,height/2);

}