Tuesday, February 3, 2026
HomeLanguagesJavascriptp5.js noLights() Function

p5.js noLights() Function

The noLights() function in p5.js is used to remove all lights in the sketch for the materials that would be rendered after this function. Any calls to light functions made after this would again re-enable the lights in the sketch.
Syntax: 
 

noLights()

Parameters: This function does not accept any parameters.
Below examples illustrates the noLights() function in p5.js:
Example 1: 
 

javascript




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 checkbox 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);
}


Output: 
 

toggle-noLights

Example 2: 
 

javascript




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 checkbox 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);
}


Output: 
 

toggle-two-ambient-noLights

Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
Reference: https://p5js.org/reference/#/p5/noLights
 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32478 POSTS0 COMMENTS
Milvus
124 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11980 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12066 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6935 POSTS0 COMMENTS
Umr Jansen
6919 POSTS0 COMMENTS