如何控制处理中显示了多少次?

发布于 2025-01-17 20:17:12 字数 402 浏览 3 评论 0 原文

void setup() {
  background(0);
  fullScreen();
}

void draw() {
  int g = 0;
  float cCount = map(mouseY, 0, height, 1, 20);
  for (int i = 0; i < width; i+=50) {
    while(g < cCount) {
     circle(i, mouseY, 20); 
    }
  }
}


所以我想做的是改变移动鼠标时圆圈在屏幕上显示的次数。当鼠标向下移动时,屏幕上会显示更多的圆圈,它们的 Y 坐标相同,但每个圆圈之间的距离为 50。当我向上移动鼠标时,显示的圆圈会减少。最大圈数为 20,最小圈数为 1。我不知道如何设置一种方法,让移动鼠标时改变圈数?

void setup() {
  background(0);
  fullScreen();
}

void draw() {
  int g = 0;
  float cCount = map(mouseY, 0, height, 1, 20);
  for (int i = 0; i < width; i+=50) {
    while(g < cCount) {
     circle(i, mouseY, 20); 
    }
  }
}


So what I'm trying to do is change the number of times circles are shown on the screen as I move the mouse. When the mouse moves down, more circles are shown on the screen all with the same Y coordinate but the distance between each circle is 50. As I move the mouse up, less circles are shown. Max circles is 20 and min is 1. I don't know how to set up a way for the number of circles to change as I move the mouse?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在夏天 2025-01-24 20:17:12

我认为你的方法是正确的,但是你的代码有一些与问题本身无关的错误。

在您的 while (g 循环中,gcCount 都没有更新,导致无限循环,但您不这样做无论如何,确实需要 while 循环。

以下应该可以工作(但我自己没有检查运行代码,所以它可能有一些错误。

void draw() {
  int circleCount = round(map(mouseY, 0, height, 1, 20));
  for (int i = 0; i < circleCount; i+=1) {
   circle(i*50, mouseY, 20); 
  }
}

I think your approach is correct, but your code has some bugs that are not related to the problem itself.

In your while (g < cCount) loop, neither g nor cCount is updated, resulting in an infinite loop, but you don't really need that while loop anyway.

The following should work (but I haven't checked running the code myself, so it might have some bugs.

void draw() {
  int circleCount = round(map(mouseY, 0, height, 1, 20));
  for (int i = 0; i < circleCount; i+=1) {
   circle(i*50, mouseY, 20); 
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文