Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

p5.js | radians() Function

  • Last Updated : 22 Apr, 2019

The radians() function in p5.js is used to convert a given degree measurement value to its corresponding value in radians.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

radians( degrees )

Parameters: This function accepts single parameter degrees which is to be converted into radians.

Return Value: It returns the converted radians value of angle.



Below programs illustrate the radians() function in p5.js:

Example 1: This example uses radians() function to convert a given degree to its corresponding 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);

Output:

Example 2: This example uses radians() function to convert a given degree to its corresponding 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);
}  

Output:

Reference: https://p5js.org/reference/#/p5/radians




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!