The constrain() function in p5.js is used to constrain a number between a given minimum and maximum limit.
constrain( n, low, high )
Parameters: This function accept three parameters as mentioned above and described below:
- n: It is a number which denotes the value that has to be constrained.
- low: It is a number which denotes the minimum limit to which the number is constrained.
- high: It is a number which denotes the maximum limit to which the number is constrained.
Return Value: It returns a number with the constrained value.
The example below illustrates the constrain() function in p5.js:
Online editor: https://editor.p5js.org/
- How to get the function name inside a function in PHP ?
- PHP | Ds\Set add() Function
- PHP | ord() Function
- D3.js | d3.max() function
- PHP | cos( ) Function
- p5.js | sin() function
- p5.js | tan() function
- p5.js | log() function
- PHP | Ds\Set xor() Function
- PHP | each() Function
- p5.js | cos() function
- PHP | min( ) Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.