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


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

p5.j​​s中的hour()函數用於從係統時鍾返回當前小時。它返回一個介於0到23之間的整數值。

用法:

hour()

參數:該函數不接受任何參數。


返回值:此函數返回代表當前小時的整數值。

以下示例程序旨在說明p5.js中的hour()函數:

例:本示例使用hour()函數從係統時鍾返回當前小時。

function setup() { 
  
    // Create Canvas of size 270*80 
    createCanvas(270, 80); 
} 
  
function draw() { 
      
    // Set the background color 
    background(220); 
      
    // Initialize the parameter with 
    // current hour 
    let h = hour(); 
      
    // Set the font size 
    textSize(16); 
      
    // Set the font color 
    fill(color('red')); 
      
    // Display result 
    text("Current hour is : " + h, 50, 30); 
}

輸出:

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



相關用法


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