p5.js中的createCamera()函數用於創建p5.Camera對象,並告訴渲染器將其用作當前相機。它返回新創建的相機對象。
用法:
createCamera()
參數:此函數不接受任何參數。
返回值:它返回一個p5.Camera對象,該對象表示新創建的相機。
以下示例說明了p5.js中的createCamera()函數:
javascript
let currCamera;
function setup() {
createCanvas(500, 300, WEBGL);
helpText = createP("Click on the buttons to create"+
"a camera and position it");
helpText.position(20, 0);
// Create three buttons for setting
// a new camera for three directions
newCameraBtn = createButton("Left Camera");
newCameraBtn.position(20, 40);
newCameraBtn.mouseClicked(createLeftCamera);
newCameraBtn = createButton("Middle Camera");
newCameraBtn.position(170, 40);
newCameraBtn.mouseClicked(createMiddleCamera);
newCameraBtn = createButton("Right Camera");
newCameraBtn.position(320, 40);
newCameraBtn.mouseClicked(createRightCamera);
}
function createLeftCamera() {
// Create a new camera using createCamera()
// and set its position
currCamera = createCamera();
currCamera.setPosition(-75, 0, 250);
}
function createMiddleCamera() {
// Create a new camera using createCamera()
// and set its position
currCamera = createCamera();
currCamera.setPosition(0, 0, 250);
}
function createRightCamera() {
// Create a new camera using createCamera()
// and set its position
currCamera = createCamera();
currCamera.setPosition(75, 0, 250);
}
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);
}
輸出:
在線編輯: https://editor.p5js.org/
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
參考: https://p5js.org/reference/#/p5/createCamera
相關用法
- PHP dir()用法及代碼示例
- PHP Ds\Set add()用法及代碼示例
- PHP next()用法及代碼示例
- PHP Ds\Set first()用法及代碼示例
- p5.js arc()用法及代碼示例
- PHP Ds\Set last()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- PHP exp()用法及代碼示例
- p5.js hex()用法及代碼示例
- PHP Ds\Set contains()用法及代碼示例
- p5.js nfs()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js mag()用法及代碼示例
- p5.js pan()用法及代碼示例
- p5.js value()用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js | createCamera() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。