舞台

4. 画布

4.2. 缩放画布


resizeCanvas()

示例:

▶️运行示例代码



function setup() {
  createCanvas(windowWidth, windowHeight);
}
function draw() {
  background(0, 100, 200);
}
function windowResized() {
  resizeCanvas(windowWidth, windowHeight);
}

舞台区显示的画布内容如下:


Description

Resizes the canvas to given width and height. The canvas will be cleared and draw will be called immediately, allowing the sketch to re-render itself in the resized canvas.

Syntax

resizeCanvas(w, h, [noRedraw])

Parameters

  • w
     
    Number: 

    width of the canvas

  • h
     
    Number: 

    height of the canvas

  • noRedraw
     
    Boolean: 

    don't redraw the canvas immediately

     (Optional)