Resizes the canvas to a given width and height.
resizeCanvas()
immediately clears the canvas and calls redraw(). It's common to call resizeCanvas()
within the body of windowResized() like so:
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
The first two parameters, width
and height
, set the dimensions of the canvas. They also the values of the width and height system variables. For example, calling resizeCanvas(300, 500)
resizes the canvas to 300×500 pixels, then sets width to 300 and height 500.
The third parameter, noRedraw
, is optional. If true
is passed, as in resizeCanvas(300, 500, true)
, then the canvas will be canvas to 300×500 pixels but the redraw() function won't be called immediately. By default, redraw() is called immediately when resizeCanvas()
finishes executing.
示例
语法
resizeCanvas(width, height, [noRedraw])
参数
width of the canvas.
height of the canvas.
whether to delay calling redraw(). Defaults to false
.