Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • p5.js-Environment
  • p5.js-Color
  • p5.js-Shape
  • p5.js-Constants and Structure
  • p5.js-DOM and Rendering
  • p5.js-Transform
  • p5.js-Data
  • p5.js-Events
  • p5.js-Image
  • p5.js-IO
  • p5.js-Math
  • p5.js-Typography
  • p5.js-Lights & Camera
  • JavaScript
  • Web Technology
Open In App
Next Article:
p5.js spotLight() Method
Next article icon

p5.js spotLight() Method

Last Updated : 01 Sep, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

The spotLight() function in p5.js is used to create a spotlight with a given color, position, direction of light, angle and concentration. A scene can have a maximum of 5 spotlights active at one time. The coordinates of the spotlight can be set according to the below-given diagram.

Syntax: This method can be used with multiple parameters depending on the syntax.

spotLight(v1, v2, v3, x, y, z, rx, ry, rz, [angle], [conc]) spotLight(color, position, direction, [angle], [conc]) spotLight(v1, v2, v3, position, direction, [angle], [conc]) spotLight(color, x, y, z, direction, [angle], [conc]) spotLight(color, position, rx, ry, rz, [angle], [conc]) spotLight(v1, v2, v3, x, y, z, direction, [angle], [conc]) spotLight(v1, v2, v3, position, rx, ry, rz, [angle], [conc]) spotLight(color, x, y, z, rx, ry, rz, [angle], [conc])

Parameters: This function accept fifteen parameters as mentioned above and described below:

  • v1: It is a number which determines the red or hue value relative to the current color mode.
  • v2: It is a number which determines the green or saturation value relative to the current color mode.
  • v3: It is a number which determines the blue or brightness value relative to the current mode.
  • x: It is the position of the light on the x-axis.
  • y: It is the position of the light on the y-axis.
  • z: It is the position of the light on the z-axis.
  • rx: It is the direction of light in the x-axis.
  • ry: It is the direction of light in the y-axis.
  • rz: It is the direction of light in the z-axis.
  • angle: It provides the angle for light. The default value is PI/3.
  • conc: It specifies the concentration value for the light. The default value is 100.
  • color: It specifies the color of the light. It can either be color Array, CSS color string, or p5.Color value.
  • position: It is a p5.Vector which specifies the position of the light.
  • direction: It is a p5.Vector which specifies the direction of the light.

Below examples illustrates the spotLight() function in p5.js:

Example 1: This example show the spotlight at one specific position.

JavaScript
function setup() {      // Creating canvas with width   // and height of 100   createCanvas(100, 100, WEBGL); }  function draw() {    // Setting background colour   // to black   background(0);      // Setting the spotlight   spotLight(0, 250, 0, 20, 20,             100, 0, 0, -1, Math.PI );   noStroke();      // Drawing a sphere to show   // the spotlight   sphere(40); } 

  

Output:


 


 

Example 2: This example illustrates how to change the spotlight position based on the mouse movement.


 

JavaScript
function setup() {      // Creating canvas with width   // and height to 100   createCanvas(100, 100, WEBGL); }  function draw() {   // Setting background colour   // to black   background(0);      // Getting position based   // on mouse movement   let locX = mouseX - width / 2;   let locY = mouseY - height / 2;      // Setting the spotlight   spotLight(0, 250, 0, locX, locY,             100, 0, 0, -1, Math.PI );   noStroke();      // Drawing a sphere to show    // the spotlight   sphere(40); } 

  

Output:


 


Reference:https://p5js.org/reference/#/p5/spotLight
 


Next Article
p5.js spotLight() Method

A

aman neekhara
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-p5.js

Similar Reads

    p5.js pointLight() Function
    The pointLight() function in p5.js is used to create a point lights with the specified color and position in the scene. A scene can have a maximum of 5 active point lights at a time. Syntax: pointLight( v1, v2, v3, x, y, z ) OR pointLight( v1, v2, v3, position ) OR pointLight( color, x, y, z ) OR po
    3 min read
    jQuery slice() Method
    The slice() is an inbuilt method in jQuery that is used to select a subset of elements based on its index. The subset is a set that may be a part of a large set. Syntax: $(selector).slice(para1, para2)Parameter: It accepts two parameters which are specified below- para1: It specifies where to start
    1 min read
    jQuery position() Method
    The position() method is an inbuilt method in jQuery that is used to find the position of the first matched element relative to its parent element in the DOM tree. Syntax: $(selector).position()Parameters: This method does not contain any parameters. Return Value: This method returns the position of
    1 min read
    JavaScript String Search Methods
    A string is a sequence of characters used to represent text or data, strings can be enclosed within single or double quotes. Here we are using some common approaches to search for a particular string/character from our given string. Below are the approaches to search strings in JavaScript: Table of
    3 min read
    Collect.js search() Method
    The search() method is used to search the given element in collection and returns its key if it exists. If the element is not found then it returns false. Syntax: collect(array).search(element) Parameters: The collect() method takes one argument that is converted into the collection and then search(
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences