Saturday, June 15, 2013

Processing code sample: draw Text with Fonts

Example to draw text with installed fonts.

draw Text with Fonts
draw Text with Fonts


PFont fontBitstreamCharter20;
PFont fontBitstreamCharterBoldItalic20;
PFont fontDejaVuSans16;

void setup() {
  size(600, 300);
  background(255);
  
  //Create fonts
  fontBitstreamCharter20 = createFont("Bitstream Charter", 20, true);  //name, size, smooth
  fontBitstreamCharterBoldItalic20 = createFont("Bitstream Charter Bold Italic", 20);    //name, size
  fontDejaVuSans16 = createFont("DejaVu Sans", 16);          //name, size
  
  fill(0); 
  
  textFont(fontBitstreamCharter20);
  text("fontBitstreamCharter20", 10, 25);
  textFont(fontBitstreamCharter20, 16);
  text("fontBitstreamCharter20, 16", 10, 50);
  
  textFont(fontBitstreamCharterBoldItalic20);
  text("fontBitstreamCharterBoldItalic20", 10, 75);
  textFont(fontBitstreamCharterBoldItalic20, 32);
  text("fontBitstreamCharterBoldItalic20, 32", 10, 100);
  
  textFont(fontDejaVuSans16);
  text("fontDejaVuSans16", 10, 125);
  textFont(fontDejaVuSans16, 32);
  text("fontDejaVuSans16, 32", 10, 150);
}

void draw() {
}

No comments:

Post a Comment