p5.js cylinder() Function

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:
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() { // Create Canvas of size 600*600 createCanvas(600, 600, WEBGL); } function draw() { // Set background color background(200); // Set fill color of cylinder fill('green'); // Call to cylinder function 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() { // Create Canvas of size 600*600 createCanvas(600, 600, WEBGL); } function draw() { // Set background color background(200); // Set fill color of cylinder fill('yellow'); // Rotate rotateX(frameCount * 0.01); rotate(frameCount*0.03); // Call to cylinder function cylinder(140, 205, 24, 16, true); } |
Output:
Reference: https://p5js.org/reference/#/p5/cylinder
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek 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!




