當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


p5.js sphere()用法及代碼示例

p5.j​​s中的sphere()函數用於繪製具有給定半徑的球體。

用法:

sphere( radius )

參數:該函數接受單個參數的半徑,該半徑存儲球體的半徑。


以下程序說明了p5.js中的sphere()函數:

示例1:本示例使用sphere()函數繪製圓。

function setup() { 
      
    // Create Canvas of size 600*600 
    createCanvas(600, 600, WEBGL); 
} 
   
function draw() { 
      
    // Set background color 
    background(200); 
     
    // Set filled color of sphere 
    fill('green'); 
     
    // sphere() function called 
    sphere(100); 
}

輸出:

示例2:本示例使用sphere()函數繪製圓。

function setup() { 
      
    // Create Canvas of size 600*600 
    createCanvas(600, 600, WEBGL); 
} 
   
function draw() { 
      
    // Set background color 
    background(200); 
     
    // Set filled color of sphere 
    fill('yellow'); 
     
    // Rotate  
    rotateX(frameCount * 0.01); 
    rotate(frameCount*0.03); 
     
    // sphere() function called 
    sphere(140); 
}

輸出:

參考: https://p5js.org/reference/#/p5/sphere



相關用法


注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 p5.js | sphere() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。