p5.js setCamera() Function Last Updated : 24 Aug, 2023 Comments Improve Suggest changes Like Article Like Report The setCamera() function in p5.js is used to set the renderer's current camera to the given p5.Camera object. This can be used to switch to multiple cameras. Syntax: setCamera( cam ) Parameters: This function accept a single parameter as mentioned above and described below: cam: It is a p5.Camera object that the function will change the camera to. The example below illustrates the setCamera() function in p5.js:Example: javascript let cameras = []; let currCameraIndex = 0; function setup() { createCanvas(600, 400, WEBGL); helpText = createP( "Click on the buttons to switch to the"+ " next camera of the sketch" ); helpText.position(20, 0); // Button to switch to the next camera // in the scene newCameraBtn = createButton("Switch to Next Camera"); newCameraBtn.position(20, 40); newCameraBtn.mouseClicked(switchActiveCamera); // Create 5 cameras and store into array for (let i = 0; i < 5; i++) { cameras[i] = createCamera(); // Randomly set the position the camera // is looking at using setPosition() randomX = floor(random(-100, 100)); randomY = floor(random(-100, 100)); cameras[i].setPosition(randomX, randomY, 350); } } function switchActiveCamera() { // Increment the camera index if (currCameraIndex < 4) currCameraIndex += 1; else currCameraIndex = 0; // Set the camera from the camera array // to that index setCamera(cameras[currCameraIndex]); } function draw() { clear(); orbitControl(); normalMaterial(); // Create three boxes at three positions translate(-150, 0); box(65); translate(150, 0); box(65); translate(150, 0); box(65); } 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/setCamera Comment More infoAdvertise with us Next Article p5.js setCamera() Function sayantanm19 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-p5.js Similar Reads p5.js setRed() Function The setRed() function in p5.js is used to set the red color value in RGB color mode. It sets the first value of RGB format. Syntax:setRed(red)Parameters:red: This parameter stores the new red value.Example 1: This example uses setRed() function to set red value of RGB color format. javascript/* decl 2 min read p5.js save() Function The save() function in p5.js is used to save to the file system by prompting a download to the computer. This function can be used to save text, images, JSON, CSV, wav, or HTML files. The default option is to save the current canvas as an image.The first parameter of the function can be specified va 3 min read p5.js | setBuffer() Function The setBuffer() function is an inbuilt function in p5.js library. This function is used to reset the buffer with the current buffer. Syntax: setBuffer( buf ) Note: All the sound-related functions only work when the sound library is included in the head section of the index.html file. Parameter: This 1 min read p5.js setBlue() Function The setBlue() function in p5.js is used to set the blue color value in RGB color mode. It sets the third value of the RGB format. Syntax:setBlue(blue)Parameters: The function accepts a single parameter as mentioned above and described below: blue: This parameter stores the new blue value.Example 1: 2 min read p5.js | setPath() Function The setPath() function is an inbuilt function in p5.js library. This function is used to reset the source for the SoundFile of new path. Syntax: setPath(path, callback) Note: All the sound-related functions only work when the sound library is included in the head section of the index.html file. Para 1 min read Like