p5.js | box() Function
The box() function in p5.js is used to draw a box with given height, width and the depth.
Syntax:
box( width, height, depth, detailX, detailY )
Parameters: This function accepts five parameters as mentioned above and described below:
Below programs illustrate the box() function in p5.js:
Example 1: This example uses box() function to draw a box.
function setup() { // Create Canvas of size 600*600 createCanvas(600, 600, WEBGL); } function draw() { // Set background color background(200); // Set fill color of box fill('green'); // box() function box(300, 400, 200); } |
Output:

Example 2: This example uses box() function to draw a box.
function setup() { // Create Canvas of size 600*600 createCanvas(600, 600, WEBGL); } function draw() { // Set background color background(200); // Set fill color of box fill('yellow'); // Rotate rotateX(frameCount * 0.01); rotate(frameCount*0.03); // box() function called box(140, 130, 120); } |
Output:

Reference: https://p5js.org/reference/#/p5/box
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- p5.js | hex() function
- PHP | pi( ) Function
- D3.js | d3.max() function
- p5.js | str() function
- p5.js | arc() Function
- PHP | pow( ) Function
- PHP | Ds\Set last() Function
- PHP | Ds\Set first() Function
- p5.js | sin() function
- PHP | Ds\Set add() Function
- p5.js | log() function
- p5.js | tan() function
- D3.js | d3.map.set() 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 contribute@geeksforgeeks.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.



