p5.js textureMode() Method
Last Updated :
04 Mar, 2021
The textureMode() function in p5.js is uses to set the coordinate space for texture mapping. This function works on the WEBGL mode. The IMAGE mode refers to the mapping the actual coordinates of the image. The NORMAL mode refers to the mapping of the normalized space of values ranging from 0 to 1.
Syntax:
textureMode(mode)
Parameters: This function accepts a single parameter as mentioned above and described below:
- mode: This is a constant that sets the mode of the texture mapping. It can have two values, IMAGE or NORMAL. The default is the IMAGE mode.
The below example illustrates the textureMode() function in p5.js:
Example:
Javascript
let img;
function preload() {
img =
loadImage( 'images/gfg_logo.jpg' );
}
function setup() {
createCanvas(500, 300, WEBGL);
}
function draw() {
texture(img);
textureMode(NORMAL);
beginShape();
vertex(-100, -100, 0, 0);
vertex(100, -100, 1, 0);
vertex(100, 100, 1, 1);
vertex(-100, 100, 0, 1);
endShape();
}
|
Output:
Reference:https://p5js.org/reference/#/p5/textureMode
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...