p5.js min() function
Last Updated :
23 Aug, 2023
The min() function in p5.js is used to get the minimum value from the sequence of numbers.
Syntax:
min(a, b)
or
min(arr)
Parameters: The min(a, b) function accepts two parameters which are two different number and compared to get minimum value among them. The min(arr) function accepts a single parameter array.
Return Value: It returns the minimum value among the different numbers.
Below program illustrates the min() function in p5.js:
Example: This example uses min() function to get the minimum value.
function setup() {
createCanvas(350, 130);
}
function draw() {
background(220);
let u = min(1, 3);
let v = min(1, 1);
let w = min(5, 9);
let x = min(2, 3.9);
let y = min(1.5, 3.2);
textSize(16);
fill(color( 'red' ));
text( "Minimum value between (1, 3) is: " + u, 50, 30);
text( "Minimum value between (1, 1) is: " + v, 50, 50);
text( "Minimum value between (5, 9) is: " + w, 50, 70);
text( "Minimum value between (2, 3.9) is: " + x, 50, 90);
text( "Minimum value between (1.5, 3.2) is: " + y, 50, 110);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/min
Share your thoughts in the comments
Please Login to comment...