cart253-2018

Graphics / CART 253 / Fall 2018 / Pippin Barr

Displaying text


In this module


Why text?

???


text()

var helloWorld = "Hello, Word!";
text(helloWorld, width/2, height/2);


textSize()

var helloWorld = "Hello, Word!";
textSize(64);
text(helloWorld, width/2, height/2);


textAlign()

textAlign(LEFT);
textAlign(CENTER);
textAlign(RIGHT);


textAlign()

textAlign(LEFT,TOP);
textAlign(LEFT,CENTER);
textAlign(LEFT,BOTTOM);


Quiz…

textAlign(CENTER,CENTER);
var appropriateText = "Stuck in the middle with you.";
text(appropriateText, width/2, height/2);

textAlign(RIGHT, BOTTOM);
var appropriateText = "Stuck in the bottom-right with you.";
text(appropriateText, width, height);

textLeading()

textSize(24);
textLeading(24);
textAlign(LEFT,CENTER);
text("Line 1\nLine 2\nLine 3", width/2, height/2);

???


textFont()

textFont("Courier");
textSize(32);
text("Hello, Courier!", 0, height/2);

???


loadFont()

var myFont;

function preload() {
  myFont = loadFont("assets/fonts/myCoolFont.ttf");
}

textFont() with a loaded font

var myFont;

function preload() {
  myFont = loadFont("assets/fonts/myCoolFont.ttf");
}

function setup() {
  createCanvas(500,500);
  textFont(myFont);
  textSize(32);
  textAlign(CENTER,CENTER);
}

function draw() {
  text("Hello, My Cool Font!", width/2, height/2);
}

Text!


Fin.