???
text()
text()
commandvar helloWorld = "Hello, Word!";
text(helloWorld, width/2, height/2);
–
text()
takes three parameters:textSize()
textSize()
var helloWorld = "Hello, Word!";
textSize(64);
text(helloWorld, width/2, height/2);
–
textSize()
takes one argument, the size of the text to displaytextAlign()
textAlign(LEFT);
textAlign(CENTER);
textAlign(RIGHT);
–
LEFT
, CENTER
, or RIGHT
(the default is LEFT
)textAlign()
textAlign
textAlign(LEFT,TOP);
textAlign(LEFT,CENTER);
textAlign(LEFT,BOTTOM);
–
TOP
, CENTER
, and BOTTOM
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()
textLeading()
textSize(24);
textLeading(24);
textAlign(LEFT,CENTER);
text("Line 1\nLine 2\nLine 3", width/2, height/2);
–
textSize()
textLeading(32)
–
textLeading(24 * 1.5)
???
\n
characters in it?\n
is a special code for “carriage return”textFont()
text()
will use a sans-serif fonttextFont()
textFont()
textFont("Courier");
textSize(32);
text("Hello, Courier!", 0, height/2);
???
loadFont()
.ttf
and .otf
var myFont;
function preload() {
myFont = loadFont("assets/fonts/myCoolFont.ttf");
}
preload()
function so it is loaded before our program runstextFont()
with a loaded fonttextFont()
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);
}