p5.js中的torus()函數用於繪製具有給定圓環半徑和管半徑的圓環。
用法:
torus( radius, tubeRadius, detailX, detailY )
參數:該函數接受上述和以下所述的四個參數:
- radius:此參數存儲圓環的半徑。
 - tubeRadius:此參數存儲管的半徑。
 - detailX:此參數以x維度存儲段數。
 - detailY:此參數以y維存儲段數。
 
以下程序說明了p5.js中的torus()函數:
示例1:本示例使用torus()函數繪製具有給定圓環半徑和管半徑的圓環。
function setup() { 
      
    // Create Canvas of size 600*600 
    createCanvas(600, 600, WEBGL); 
} 
   
function draw() { 
      
    // Set background color 
    background(200); 
     
    // Set fill color of torus 
    fill('green'); 
     
    // Call to torus function 
    torus(90, 35, 12, 12); 
}輸出:

示例2:本示例使用torus()函數繪製具有給定圓環半徑和管半徑的圓環。
function setup() { 
      
    // Create Canvas of size 600*600 
    createCanvas(600, 600, WEBGL); 
} 
   
function draw() { 
      
    // Set background color 
    background(200); 
     
    // Set fill color of torus 
    fill('yellow'); 
     
    // Rotate  
    rotateX(frameCount * 0.01); 
    rotate(frameCount*0.05); 
     
    // Call to torus function 
    torus(90, 35); 
}輸出:

參考: https://p5js.org/reference/#/p5/torus
相關用法
- PHP pow( )用法及代碼示例
 - PHP end()用法及代碼示例
 - d3.js d3.map.set()用法及代碼示例
 - p5.js red()用法及代碼示例
 - p5.js hue()用法及代碼示例
 - PHP cos( )用法及代碼示例
 - p5.js min()用法及代碼示例
 - d3.js d3.hsl()用法及代碼示例
 - PHP pos()用法及代碼示例
 - PHP key()用法及代碼示例
 - d3.js d3.min()用法及代碼示例
 - p5.js cos()用法及代碼示例
 
注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 p5.js | torus() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
