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


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

exp()函數將n的值(任意數字)返回到歐拉數e(2.71828…),該數字升為冪n(e^n)。

用法:

exp(n)

參數:此方法接受單個參數n,即數字值。

返回值:它返回給定編號的(e^n)。

範例1:



Javascript

function setup() {  
   
    // Create Canvas of size 270*80  
    createCanvas(600, 300);  
}  
   
function draw() {  
       
    // Set the background color  
    background(220);  
       
    // Initialize the parameter and  
    // return the value of the function 
    let n = exp(1.1) 
    let m = exp(3.3) 
       
    // Set the size of text  
    textSize(16);  
       
    text( "Result in Eular number will be:" + n, 50, 50); 
    text( "Result in Eular number will be:" + m, 50, 80); 
       
}

輸出:

範例2:

Javascript

function setup() {  
   
    // Create Canvas of size 270*80  
    createCanvas(600, 500);  
}  
   
function draw() {  
    let x, m; 
    let step = 50 
      
    // Set the background color  
    background(220);  
   
    // Initialize the parameter and return 
    // the value of the function 
    // For loop is set from numbert 0 to 10. 
    for( x = 0; x <= 10; x++) { 
           
        // The return value of exp() function 
        m = exp(x) 
        text( "Result for " + x +  
             ":" + m, 50, step); 
        
        step = step + 30; 
      } 
       
      // Set the size of text  
      textSize(17);  
       
      // Set the text color  
      fill(color('blue'));  
}

輸出:

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

相關用法


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