p5.js中的angleMode()函數用於設置解釋角度的模式。可以將其設置為度或弧度。使用角度作為參數的所有函數都將遵循此函數設置的角度模式。
用法:
angleMode( mode )
參數:該函數接受如上所述和以下描述的單個參數:
- mode:該常數可用於設置解釋角度的模式。它可以具有DEGREES或RADIANS的值。
以下示例說明了p5.js中的angleMode()函數:
javascript
let angleModeSelected;
function setup() {
createCanvas(400, 300);
textSize(18);
// Set the default angle to DEGREES
angleModeSelected = DEGREES;
// Create a button for toggling the angle mode
angleModeToggler = createButton("Toggle Angle Mode");
angleModeToggler.position(30, 40);
angleModeToggler.mouseClicked(() => {
if (angleModeSelected == DEGREES) angleModeSelected = RADIANS;
else angleModeSelected = DEGREES;
});
// Create a slider for changing the current angle
angleSlider = createSlider(-180, 180, 0, 1);
angleSlider.position(30, 120);
}
function draw() {
clear();
// Get the angle from the slider
let angleToRotate = angleSlider.value();
// Convert the angle to radians
// for demonstration
let angleInRadians = (angleToRotate / 57.295).toFixed(3);
text("Angle Mode Selected:" + angleModeSelected, 20, 20);
text("Current value of rotation:" + angleToRotate + " degrees", 20, 80);
text("Current value of rotation:" + angleInRadians + " radians", 20, 100);
// Set the angle mode
// based on the selected mode
angleMode(angleModeSelected);
translate(width / 3, height / 1.5);
// Rotate the shape according to
// the angle specified
rotate(angleToRotate);
// Draw the rectangle that
// would be rotated
rect(0, 0, 100, 25);
}
輸出:
在線編輯: https://editor.p5js.org/
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
參考: https://p5js.org/reference/#/p5/angleMode
相關用法
- 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 | angleMode() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。