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


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

p5.j​​s中的noLights()函數用於刪除草圖中該函數之後將渲染的材質中的所有光源。此後進行的任何對燈光函數的調用都會再次re-enable草圖中的燈光。

用法:

noLights()

參數:該函數不接受任何參數。



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

範例1:

let newFont; 
let nolightsEnable = false; 
  
function preload() { 
  newFont = loadFont('fonts/Montserrat.otf'); 
} 
  
function setup() { 
  createCanvas(600, 300, WEBGL); 
  textFont(newFont, 18); 
  
  nolightsEnableCheck = createCheckbox( 
        "Enable noLights", false); 
  
  nolightsEnableCheck.position(20, 60); 
  
  // Toggle default light 
  nolightsEnableCheck.changed(() => { 
    nolightsEnable = !nolightsEnable; 
  }); 
} 
  
function draw() { 
  background("green"); 
  text("Click on the checbox to toggle the "
       + "noLights() function.", -285, -125); 
  noStroke(); 
  
  // Ambient light with red color 
  ambientLight('red'); 
  
  // First sphere in the sketch 
  translate(-100, 0, 0); 
  sphere(50); 
  
  translate(100, 0, 0); 
  
  // If checkbox is enabled 
  if (nolightsEnable) { 
  
    // Disable all lights after this 
    noLights(); 
  
    text("Lights disabled for second"
          + " sphere", -285, 125); 
  } 
  else { 
    text("Lights enabled for second"
          + " sphere", -285, 125); 
  } 
  
  // Second sphere in the sketch 
  translate(100, 0, 0); 
  sphere(50); 
}

輸出:
toggle-noLights

範例2:

let newFont; 
let nolightsEnable = false; 
  
function preload() { 
  newFont = loadFont('fonts/Montserrat.otf'); 
} 
  
function setup() { 
  createCanvas(600, 300, WEBGL); 
  textFont(newFont, 18); 
  
  nolightsEnableCheck = createCheckbox( 
           "Enable noLights", false); 
  
  nolightsEnableCheck.position(20, 60); 
  
  // Toggle default light 
  nolightsEnableCheck.changed(() => { 
    nolightsEnable = !nolightsEnable; 
  }); 
} 
  
function draw() { 
  background("green"); 
  text("Click on the checbox to toggle the"
    + " noLights() function.", -285, -125); 
  noStroke(); 
  
  // Ambient light with red color 
  ambientLight('red'); 
  
  // First sphere in the sketch 
  translate(-100, 0, 0); 
  sphere(50); 
  
  translate(100, 0, 0); 
  
  // If checkbox is enabled 
  if (nolightsEnable) { 
  
    // Disable all lights after this 
    noLights(); 
  
    text("Red ambient light disabled for"
        + " second sphere", -285, 125); 
  } 
  else { 
    text("Red ambient light enabled for"
        + " second sphere", -285, 125); 
  } 
  
  ambientLight('blue'); 
  
  // Second sphere in the sketch 
  translate(100, 0, 0); 
  sphere(50); 
}

輸出:
toggle-two-ambient-noLights

在線編輯: https://editor.p5js.org/

環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/

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




相關用法


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