如何调整p5.Graphic对象的大小?

时间:2017-11-18 07:50:29

标签: p5.js

在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函数?

谢谢!

2 个答案:

答案 0 :(得分:1)

如果你想调整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; } 的大小,你可以创建一个新的,然后将旧的绘制到新的。

Here就是一个例子:

filter(None, [x.strip() for x in str_list])

答案 1 :(得分:0)

在通过“ createGraphics”创建的图形对象上使用resizeCanvas似乎可以拉伸图形,而不是调整缓冲区的大小。 现在,调整图形对象大小的最佳方法是直接设置width和height属性。

// 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