p5.js textStyle() Function
The textStyle() function in p5.js is used to set or return the style of the text for system fonts to NORMAL, ITALIC, BOLD, or BOLDITALIC. This may be overridden by CSS styling.
Syntax:
textStyle(style)
or
textStyle()
Parameters: This function accepts a single parameter style that stores the styling Constant.
The below programs illustrate the textStyle() function in p5.js.
Example 1: This example uses the textStyle() function to set the style of text.
javascript
function setup() {
createCanvas(380, 170);
}
function draw() {
let string = "GeeksforGeeks" ;
background(220);
textStyle(ITALIC);
textSize(16);
text(string, 20, 30);
textStyle(BOLD);
text(string, 20, 70);
textStyle(BOLDITALIC);
text(string, 20, 110);
}
|
Output:
Example 2: This example uses the textStyle() function to return the style of text.
javascript
function setup() {
createCanvas(380, 170);
}
function draw() {
let string = "GeeksforGeeks" ;
background(220);
textStyle(BOLD);
textSize(16);
var u = textStyle();
stroke(255, 204, 0);
text( "Value of Text Style is : " + u, 50, 30);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/textStyle
Last Updated :
23 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...