当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


p5.js cone()用法及代码示例

p5.j​​s中的cone()函数用于绘制具有给定半径和高度的圆锥。

用法:

cone( radius, height, detailX, detailY, cap )

参数:该函数接受上述和以下所述的五个参数:

  • radius:此参数存储圆锥的半径。
  • height:此参数存储圆锥体的高度。
  • detailX:此参数以x维度存储段数。
  • detailY:此参数以y维存储段数。
  • cap:此参数存储是否绘制圆锥底的布尔值。

以下程序说明了p5.js中的cone()函数:


示例1:本示例使用cone()函数绘制具有给定半径和高度的圆锥。

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); 
}

输出:

示例2:本示例使用cone()函数绘制具有给定半径和高度的圆锥。

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); 
}

输出:

参考: https://p5js.org/reference/#/p5/cone



相关用法


注:本文由纯净天空筛选整理自sarthak_ishu11大神的英文原创作品 p5.js | cone() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。