p5.js lights() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The lights() function in p5.js is used to set the default ambient and directional light in the scene. The default ambient light used is ambientLight(128, 128, 128) and the directional light is directionalLight(128, 128, 128, 0, 0, -1). This function can be used to quickly add default lights in the scene.The lights() function has to be used in the draw() function of the code to remain persistent in the scene.Syntax: lights() Parameters: This function does not accept any parameters.Below examples illustrate the lights() function in p5.js:Example 1: javascript let newFont; let lightsEnable = false; function preload() { newFont = loadFont('fonts/Montserrat.otf'); } function setup() { createCanvas(600, 300, WEBGL); textFont(newFont, 18); lightsEnableCheck = createCheckbox( "Enable Default Lights", false); lightsEnableCheck.position(20, 60); // Toggle default light lightsEnableCheck.changed(() => { lightsEnable = !lightsEnable; }); } function draw() { background("green"); text("Click on the checkbox to toggle the" + " default lights.", -285, -125); noStroke(); shininess(15); specularMaterial(250); if (lightsEnable) { // Enable the default lights lights(); } sphere(80); } Output: Example 2: javascript let newFont; let lightsEnable = false; function preload() { newFont = loadFont('fonts/Montserrat.otf'); } function setup() { createCanvas(600, 300, WEBGL); textFont(newFont, 18); lightsEnableCheck = createCheckbox( "Enable Default Lights", false); lightsEnableCheck.position(20, 60); // Toggle default light lightsEnableCheck.changed(() => { lightsEnable = !lightsEnable; }); } function draw() { background("green"); text("Click on the checkbox to toggle the" + " default lights.", -285, -125); noStroke(); shininess(15); specularMaterial(250); if (lightsEnable) { // Enable the default lights lights(); } rotateX(millis() / 1000); rotateY(millis() / 1000); box(100); } Output: 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/lights Comment More infoAdvertise with us Next Article p5.js lights() Function sayantanm19 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-p5.js Similar Reads 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 par 2 min read p5.js lightness() function The lightness() function in p5.js is used to extract the HSL lightness value from a color or pixel array. Syntax: lightness(c) Parameters: This function accepts single parameter c which stores the p5.Color object, color components, or CSS color. Below programs illustrate the lightness() function in 2 min read p5.js millis() function The millis() function in p5.js is used to return the number of milliseconds from starting the program. This function is mostly used in timing events and animation sequences. Syntax: millis() Parameters: The function does not accept any parameter. Return Value: It returns the number of milliseconds f 1 min read p5.js lightFalloff() Function The lightFalloff() function in p5.js is used to set the falloff for point lights in the scene. Light falloff means the reduction of illumination with the distance of the object from the point light. It only affects elements that are created after it. The following equation is used to calculate the f 2 min read p5.js minute() function The minute() function in p5.js is used to return the current minute in the system clock. The value of minute() function lies between 0 to 59. Syntax: minute() Parameters: The function does not accept any parameter. Return Value: This function returns an integer value which represents the minute time 1 min read Like