Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

p5.js | textSize() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The textSize() function in p5.js is used to set or return the font size of text. This function is used in all subsequent calls to the text() function.

Syntax:

textSize(size)

or

textSize()

Parameters: This function accepts single parameter sizewhich stores the size of the text in terms of pixels.

Below programs illustrate the textSize() function in p5.js:

Example 1: This example uses textSize() function to set the font size of text.




function setup() {
      
    // Create Canvas of given size
    createCanvas(380, 170);
}
  
function draw() {
      
    let string = "GeeksforGeeks";
      
    // Set the background color
    background(220);
      
    // Set the text size
    textSize(30);
      
    // Set the text 
    text(string, 100, 30);
}


Output:

Example 2: This example uses textSize() function to return the font size of text.




function setup() {
      
    // Create Canvas of given size
    createCanvas(380, 170);
}
  
function draw() {
      
    let string = "GeeksforGeeks";
      
    // Set the background color
    background(220);
      
    // Set the text size
    textSize(16);
      
    // store the size of text
    var u = textSize();
      
    // Set the stroke color
    stroke(255, 204, 0);
  
    // Display result
    text("Value of Text Size is : "
            + u, 50, 30);
}


Output:

Reference: https://p5js.org/reference/#/p5/textSize


My Personal Notes arrow_drop_up
Last Updated : 16 Apr, 2019
Like Article
Save Article
Similar Reads
Related Tutorials