p5.js cylinder() Function
Last Updated :
11 Aug, 2023
The cylinder() function in p5.js is used to draw a cylinder with given radius and height.
Syntax:
cylinder( radius, height, detailX, detailY, bottomCap, topCap )
Parameters: The function accepts six parameters as mentioned above and described below:
radius: This parameter stores the radius of the surface.
height: This parameter stores the height of the surface.
detailX: This parameter stores the number of segments in x-dimension.
detailY: This parameter stores the number of segments in y-dimension.
bottomCap: This parameter stores the boolean value whether to draw bottom base of cylinder.
topCap: This parameter stores the boolean value whether to draw top base of cylinder.
Below programs illustrate the cylinder() function in p5.js:
Example 1: This example uses cylinder() function to draw a cylinder with given radius and height.
function setup() {
createCanvas(600, 600, WEBGL);
}
function draw() {
background(200);
fill( 'green' );
cylinder(100, 85, 24, 16, true , false );
}
|
Output:
Example 2: This example uses cylinder() function to draw a cylinder with given radius and height.
function setup() {
createCanvas(600, 600, WEBGL);
}
function draw() {
background(200);
fill( 'yellow' );
rotateX(frameCount * 0.01);
rotate(frameCount*0.03);
cylinder(140, 205, 24, 16, true );
}
|
Output:
Reference: https://p5js.org/reference/#/p5/cylinder
Share your thoughts in the comments
Please Login to comment...