如何控制处理中显示了多少次?
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。我不知道如何设置一种方法,让移动鼠标时改变圈数?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的方法是正确的,但是你的代码有一些与问题本身无关的错误。
在您的
while (g 循环中,
g
和cCount
都没有更新,导致无限循环,但您不这样做无论如何,确实需要 while 循环。以下应该可以工作(但我自己没有检查运行代码,所以它可能有一些错误。
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, neitherg
norcCount
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.