📜  p5.js | displayDensity()函数

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

p5.js | displayDensity()函数

p5.js 中的 displayDensity()函数用于返回当前显示草图的像素密度。

句法:

pixelDensity(density)

参数:此函数接受存储显示密度的单个参数密度

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

例子:

function setup() {
      
    // Create canvas of given size
    createCanvas(windowWidth, windowHeight);
    
    // Call the displayDensity function
    let density = displayDensity(); 
    pixelDensity(density);
}
   
function draw() {
  
    // Set the background color
    background(0, 200, 0);
      
    // Set text color
    color("green");
      
    // Set font size
    textSize(30);
      
    // Set text alignment
    textAlign(CENTER);
      
    // Set text to be add
    text("GeeksForGeeks!", windowWidth/2, windowHeight/2);
      
    // Display pixelDensity on the screen
    text("PixelDensity is " + pixelDensity(), 
            windowWidth/2, windowHeight/2+40);
}

输出:

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