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:
- Difference between alert box and confirmation box in JavaScript
- How to change Input box borders after filling the box using JavaScript ?
- How to use javascript function in check box?
- CSS | Box model
- CSS | box decoration break Property
- How to get multiple selected values of select box in php?
- How to make a placeholder for a 'select' box?
- CSS | box-sizing Property
- CSS | box-shadow Property
- How to create a Color-Box App using ReactJS?
- How to add a box-shadow on one side of an element using CSS?
- How to set the value of a select box element using JavaScript?
- How to add a new line in the alert box ?
- How to remove items from a select box ?
- What are the types of Popup box available in JavaScript ?
- How to do box shadow with progress bar style using bootstrap?
- How to align button to right side of text box in Bootstrap?
- How to create a pop-up to print dialog box using JavaScript?
- How to restrict input box to allow only numbers and decimal point JavaScript?
- How to pop an alert message box using PHP ?
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.


