La función textSize() en p5.js se usa para establecer o devolver el tamaño de fuente del texto. Esta función se utiliza en todas las llamadas posteriores a la función text().
Sintaxis:
textSize(size)
o
textSize()
Parámetros: esta función acepta un tamaño de parámetro único que almacena el tamaño del texto en términos de píxeles.
Los siguientes programas ilustran la función textSize() en p5.js:
Ejemplo 1: Este ejemplo usa la función textSize() para establecer el tamaño de fuente del texto.
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); }
Producción:
Ejemplo 2: este ejemplo utiliza la función textSize() para devolver el tamaño de fuente del texto.
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); }
Producción:
Referencia: https://p5js.org/reference/#/p5/textSize
Publicación traducida automáticamente
Artículo escrito por sarthak_ishu11 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA