椭圆没有出现在 mousePressed 函数的 for 循环中

问题描述 投票:0回答:0

我有一个 p5.js 草图,我想在 mousePressed 函数内的 for 循环内绘制一个椭圆。但是,椭圆没有按预期出现在画布上。我检查了坐标和填充颜色,但仍然没有运气。

function mousePressed() {
  // code for when button is pressed 
  if (mouseX > 270 && mouseX < 330 && mouseY > 500 && mouseY < 560) {
    for (let objY = 420; objY > height; objY--) {
      fill(255);
      ellipse(300, objY, 30, 30);
    }
  }
}

尽管尝试了各种解决方案,包括使用不同类型的循环,例如 while 循环,但我还是无法克服这个问题。即使在使用 while 循环努力解决问题后,问题仍然存在,并且椭圆的预期移动没有按预期发生。

p5.js
© www.soinside.com 2019 - 2024. All rights reserved.