在p5.js中,resizeCanvas(x, y)
是一个用于p5对象的函数,但是如果我创建了一个p5.Graphics
对象,我可以用类似的函数调整它的大小吗?
有趣的是,p5.Graphics
对象可以运行resizeGraphics()
,但没有发生任何事情(包括没有错误),并且控制台中的高度和宽度保持不变。
g = createGraphics(50, 50); //creates p5.Graphics
g.resizeCanvas(100, 100); //fails: silently without error
g.resize(100, 100); //fails: resize has not been defined
是否有其他函数,或者我是否需要实际提取响应的图形画布并调用原生javascript函数?
谢谢!
发布于 2017-11-21 11:23:26
如果你想调整一个P5.Graphics
的大小,你可以创建一个新的,然后绘制旧的到新的。
Here就是一个例子:
var pg;
function setup() {
createCanvas(1000, 1000);
pg = createGraphics(100, 100);
pg.background(100);
pg.noStroke();
pg.ellipse(pg.width/2, pg.height/2, pg.width, pg.height);
}
function draw() {
background(200);
image(pg, 0, 0);
}
function mouseClicked(){
var newPG = createGraphics(mouseX, mouseY);
newPG.image(pg, 0, 0, newPG.width, newPG.height);
pg = newPG;
}
发布于 2018-08-08 04:14:31
在使用"createGraphics“创建的图形对象上使用resizeCanvas似乎会拉伸图形,而不是调整缓冲区的大小。现在,调整图形对象大小的最好方法是直接设置宽度和高度属性。
// Some graphics object
let graphics = createGraphics(w,h);
// Now simply resize like this
graphics.width = gWidth;
graphics.height = gHeight;
正如这里所建议的:https://github.com/processing/p5.js/issues/2064#issuecomment-315503533
https://stackoverflow.com/questions/47363844
复制相似问题