📜  p5.js |地板()函数

📅  最后修改于: 2022-05-13 01:56:46.657000             🧑  作者: Mango

p5.js |地板()函数

p5.js 中的floor()函数用于计算数字的下限值。此函数映射到 JavaScript 的Math.floor() 。它计算小于或等于参数值的最接近的 int值。

句法

floor(number)

参数:该函数只接受一个参数,如上所述,如下所述:

  • number :此参数存储要计算的数字。

    下面的程序说明了 p5.js 中的floor()函数
    例子:

    function setup() {
      
        //create Canvas of size 270*80  
        createCanvas(270, 80);
    }
      
    function draw() {
        background(220);
        //initialize the parameter  
        let x = 65.67;
        //call to floor() function  
        let y = floor(x);
        textSize(16);
        fill(color('red'));
        text("Given Number is : " + x, 50, 30);
        text("Computed Number is : " + y, 50, 50);
    }
    

    输出:

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