Home / πŸ—“ Schedule / πŸ›  Examples / πŸ’« Guides / πŸ’Ž Resources

πŸ€” Conditionals {

✨ Conditionals are the key way we can make a program do different things based on the current situation! ✨

Learning objectives

Template

Modules

Vimeo playlist for Conditionals

(Inline links below are for YuJa)

Extra! Extra!

Examples

πŸ”₯ Hot tip: Text

We can store text in variables (or object properties) by using quotation marks:

let myName = "Gladiolus";

We can display text by using p5’s text() function along with some text-styling functions:

let myName = "Gladiolus";

function setup() {
    createCanvas(400, 400);
}

function draw() {
    background(0);
    
    push();
    // Set text colour with fill
    fill(255, 0, 0);
    // Set text size with textSize()
    textSize(64);
    // Set text align with textAlign()
    textAlign(CENTER, CENTER);
    // Set text styling with textStyle()
    textStyle(BOLD);
    // We can display text by just putting it directly in quotes
    text("Hi, my name is:", 200, 180);
    // We can display text inside a variable
    text(myName, 200, 220)
    pop();
}

πŸ“– Read the Typography documentation in the reference for more information. πŸ“–

}