Friday, January 16, 2026
HomeLanguagesJavascriptp5.js cone() Function

p5.js cone() Function

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() {
        
        // Create Canvas of size 600*600
        createCanvas(600, 600, WEBGL);
    }
       
    function draw() {
          
        // Set background color
        background(200);
         
        // Set fill color of cone
        fill('green');
         
        // Call to cone function
        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() {
        
        // Create Canvas of size 600*600
        createCanvas(600, 600, WEBGL);
    }
       
    function draw() {
          
        // Set background color
        background(200);
         
        // Set fill color of cone
        fill('yellow');
         
        // Rotate 
        rotateX(frameCount * 0.01);
        rotate(frameCount*0.03);
         
        // Call to cone function
        cone(90, 135, 8, 8, true);
    }

    
    

    Output:

    Reference: https://p5js.org/reference/#/p5/cone

    Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
    RELATED ARTICLES

    Most Popular

    Dominic
    32470 POSTS0 COMMENTS
    Milvus
    117 POSTS0 COMMENTS
    Nango Kala
    6837 POSTS0 COMMENTS
    Nicole Veronica
    11972 POSTS0 COMMENTS
    Nokonwaba Nkukhwana
    12052 POSTS0 COMMENTS
    Shaida Kate Naidoo
    6972 POSTS0 COMMENTS
    Ted Musemwa
    7213 POSTS0 COMMENTS
    Thapelo Manthata
    6928 POSTS0 COMMENTS
    Umr Jansen
    6906 POSTS0 COMMENTS