当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。