當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


p5.js js textureMode()用法及代碼示例

p5.j​​s中的textureMode()函數用於設置紋理映射的坐標空間。此函數在WEBGL模式下有效。圖像模式是指映射圖像的實際坐標。 NORMAL模式是指範圍為0到1的值的標準化空間的映射。

用法:

textureMode(mode)

參數:該函數接受如上所述和以下描述的單個參數:

  • mode:這是設置紋理映射模式的常量。它可以有兩個值,IMAGE或NORMAL。默認為圖像模式。

以下示例說明了p5.js中的textureMode()函數:

例:



Javascript

// Creating a global image variable 
let img; 
  
  
// Load the image in the 
// preload function 
function preload() { 
  img = 
    loadImage('images/gfg_logo.jpg'); 
} 
  
// Create the canvas 
function setup() { 
  createCanvas(500, 300, WEBGL); 
} 
  
function draw() { 
  
  // Draw the texture 
  texture(img); 
    
  // Set the mode to NORMAL 
  // for the texture   
  textureMode(NORMAL); 
    
  beginShape(); 
    
  // Adding the coordinates in NORMAL form 
  vertex(-100, -100, 0, 0); 
  vertex(100, -100, 1, 0); 
  vertex(100, 100, 1, 1); 
  vertex(-100, 100, 0, 1); 
    
  endShape(); 
}

輸出:


參考:https://p5js.org/reference/#/p5/textureMode

相關用法


注:本文由純淨天空篩選整理自_sh_pallavi大神的英文原創作品 p5.js textureMode() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。