带有自定义口罩的P5J中的图像拼贴
我正在尝试使用多个图像和口罩在P5.J中进行拼贴。我为三个图像和圆面罩写了一个简单的测试代码。输出应为三个圆圈,每个圆圈都充满不同的图像。但是,我只得到一个圆圈,里面充满了最后一个图像。有人可以帮我吗?
let newImg, graphicsCanvas;
function setup() {
createCanvas(600, 600);
noLoop();
}
function draw() {
for (let i=0; i<3; i++) {
newImg = loadImage(`images/${i}.png`, addImg);
}
}
function addImg() {
graphicsCanvas = createGraphics(width, height);
graphicsCanvas.noStroke();
graphicsCanvas.fill(255);
graphicsCanvas.circle(random(500), height/2, 150);
newImg.mask(graphicsCanvas);
image(newImg, 0, 0);
}
I'm trying to make a collage in p5.js using multiple images and masks. I wrote a simple test code for three images and circle-masks. The output should be three circles each filled with a different image. However, I only get one circle filled with the last image. Could anyone please help me?
let newImg, graphicsCanvas;
function setup() {
createCanvas(600, 600);
noLoop();
}
function draw() {
for (let i=0; i<3; i++) {
newImg = loadImage(`images/${i}.png`, addImg);
}
}
function addImg() {
graphicsCanvas = createGraphics(width, height);
graphicsCanvas.noStroke();
graphicsCanvas.fill(255);
graphicsCanvas.circle(random(500), height/2, 150);
newImg.mask(graphicsCanvas);
image(newImg, 0, 0);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论