带有自定义口罩的P5J中的图像拼贴

发布于 2025-01-24 03:20:35 字数 568 浏览 3 评论 0原文

我正在尝试使用多个图像和口罩在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文