p5.js cone() Function
Last Updated :
11 Aug, 2023
The cone() function in p5.js is used to draw a cone with given radius and height.
Syntax:
cone( radius, height, detailX, detailY, cap )
Parameters: The function accepts five parameters as mentioned above and described below:
radius: This parameter stores the radius of the cone.
height: This parameter stores the height of the cone.
detailX: This parameter stores the number of segments in x-dimension.
detailY: This parameter stores the number of segments in y-dimension.
cap: This parameter stores the boolean value whether to draw base of the cone.
Below programs illustrate the cone() function in p5.js:
Example 1: This example uses cone() function to draw a cone with given radius and height.
function setup() {
createCanvas(600, 600, WEBGL);
}
function draw() {
background(200);
fill( 'green' );
cone(90, 175, 12, 12, true );
}
|
Output:
Example 2: This example uses cone() function to draw a cone 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);
cone(90, 135, 8, 8, true );
}
|
Output:
Reference: https://p5js.org/reference/#/p5/cone
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...