p5.js | cos() function
The cos() function in p5.js is used to calculate the cosine value of an angle (taken in radian) as input parameter of the function and returns the result between -1 to 1.
Parameters: This function accepts a single parameter angle which is an angle in radian whose cosine value to be calculated.
Return Value: It returns the cosine value of an angle in radian taken as the input parameter.
Below program illustrates the cos() function in p5.js:
Example: This example uses cos() function to get cosine value of an angle in radian.
Note: In the above code, the input angle should be in radian. For converting degree angle into radian we can use the following formula:
Angles_in_radian = (π/180)*angles_in_degree