Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptp5.js Math Complete Reference

p5.js Math Complete Reference

The Math object in p5.js is used to perform mathematical operations on numbers. There are many math objects exists in p5.js which are listed below.

Calculation

Description

abs() abs() function is used to calculate the absolute value of a number.
ceil() ceil() function is used to calculate the ceil value of a number.
constrain() It is used to constrain a number between a given minimum and maximum limit.
dist() dist() function calculates the Euclidean distance in 2D or 3D.
floor() floor() function is used to calculate the floor value of a number.
lerp() lerp() function is used to find a number between two numbers.
log() It is used to get the natural logarithm (of base “e”) of any number taken as input for the parameter of log() function.
mag() mag() function is used to find the magnitude or length of a vector.
max() It is used to get the maximum value among sequence of numbers or two given numbers.
min() min() function is used to get the minimum value from the sequence of numbers.
pow() pow() function is used to calculate the power of a number to the given number.
round() round() function is used to calculate the round value of a number.
sq() sq() function is used to calculate the square value of a number.
sqrt() sqrt() function is used to get the square root of any input number.
fract() fract() function is used to find the fractional part of a number.

Vector

Description

createVector() It creates the new p5 vector which contains both magnitude and direction.

Noise

Description

noise() noise() function is used to return a number generated by Perlin noise at the given coordinates.
noiseSeed() noiseSeed() function is used to set a seed value for the noise() function.

Random

Description

randomSeed() randomSeed() function is used to return a random number each time when run the program.
random() It is used to return a random floating point number between ranges given as the parameter.
randomGaussian() It is used to return a random value fitting a Gaussian or normal distribution.

Trigonometry

Description

acos() acos() function is used to calculate the arc cosine value.
asin() asin() function is used to calculate the inverse of sine (arc sine).
atan() atan() function is used to calculate the inverse of tan() or arc tangent.
atan2() It is used to calculate the angle from a specified point of origin measured from the positive x-axis.
cos() cos() function is used to calculate the cosine value of an angle.
tan() tan() function is used to calculate the tangent value of an angle.
degrees() It converts a given radian measurement value to its corresponding value in degrees.
radians() It converts a given degree measurement value to its corresponding value in radians.
angleMode() angleMode() function is used to set the mode in which the angle is interpreted.
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments