當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


p5.js radians()用法及代碼示例


p5.j​​s中的radians()函數用於將給定的度數測量值轉換為相應的弧度值。

用法:

radians( degrees )

參數:該函數接受單個參數度,該度將轉換為弧度。


返回值:它返回角度的轉換弧度值。

以下程序說明了p5.js中的radians()函數:

示例1:本示例使用radians()函數將給定度數轉換為其對應的弧度。

function setup() {  
   
    // Creating Canvas size 
    createCanvas(450, 140);  
}  
  
function draw() {  
       
    // Set the background color  
    background(220);  
     
    // Initializing some angles in degree 
    let Deg1 = 0;  
    let Deg2 = 30;  
    let Deg3 = 60;  
    let Deg4 = 90;  
      
      
    // Calling to radians() function. 
    let A = radians(Deg1); 
    let B = radians(Deg2); 
    let C = radians(Deg3); 
    let D = radians(Deg4); 
      
    // Set the size of text  
    textSize(16);  
       
    // Set the text color  
    fill(color('red'));  
     
    // Getting converted angles into radians 
    text("Converted angle in radian is: " + A, 50, 30); 
    text("Converted angle in radian is: " + B, 50, 60); 
    text("Converted angle in radian is: " + C, 50, 90); 
    text("Converted angle in radian is: " + D, 50, 110); 
} 

輸出:

示例2:本示例使用radians()函數將給定度數轉換為其對應的弧度。

function setup() {  
   
    // Creating Canvas size 
    createCanvas(450, 140);  
}  
  
function draw() {  
       
    // Set the background color  
    background(220);  
      
    // Calling to radians() function with different 
    // degrees value as parameter 
    let A = radians(90); 
    let B = radians(180); 
    let C = radians(60); 
    let D = radians(45); 
      
    // Set the size of text  
    textSize(16);  
       
    // Set the text color  
    fill(color('red'));  
     
    // Getting converted angles in radians 
    text("Converted angle in radian is: " + A, 50, 30); 
    text("Converted angle in radian is: " + B, 50, 60); 
    text("Converted angle in radian is: " + C, 50, 90); 
    text("Converted angle in radian is: " + D, 50, 110); 
}  

輸出:

參考: https://p5js.org/reference/#/p5/radians



相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 p5.js | radians() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。