p5.js | sin() function
Last Updated :
10 Apr, 2019
The sin() function in p5.js is used to calculate the sine value of an angle in radians taken as the input parameter of the function and gives the result in between -1 to 1.
Syntax:
sin( angle )
Parameters: This function accepts a single parameter angle which is an angle in radian whose sine value is calculated.
Return Value: It returns the sine value of an angle in radian taken as the input parameter.
Below program illustrates the sin() function in p5.js:
Example: This example uses sin() function to get sine value of an angle in radian.
function setup() {
createCanvas(550, 130);
}
function draw() {
background(220);
let a = 0;
let b = 8.9;
let c = 47;
let d = 5;
let v = sin(a);
let w = sin(b);
let x = sin(c);
let y = sin(d);
textSize(16);
fill(color( 'red' ));
text( "Sine value of angle 0 (in radian) is : " + v, 50, 30);
text( "Sine value of angle 8.9 (in radian) is : " + w, 50, 50);
text( "Sine value of angle 47 (in radian) is : " + x, 50, 70);
text( "Sine value of angle 5 (in radian) is : " + y, 50, 90);
}
|
Output:
Note: In the above code, the input angle should be in radian. For converting the degree into radian use the following formula:
Angles_in_radian = (π/180)*angles_in_degree
Reference: https://p5js.org/reference/#/p5/sin
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...