p5.js | createVector() function
The createVector() function in p5.js is used to create the new p5 vector which contains both magnitude and direction. This provides a two or three-dimensional vector, specifically a geometric vector.
createVector([x], [y], [z])
Parameters: This function accepts three parameters as mentioned above and described below:
- x: This parameter stores the x component of the vector.
- y: This parameter stores the y component of the vector.
- z: This parameter stores the z component of the vector.
Below programs illustrate the createVector() function in p5.js:
Example 1: This example uses createVector() function to draw a line.
Example 2: This example uses createVector() function to draw a circle.