英文:
Random stroke weight is always bigger in draw() - Processing
问题
这里是您要翻译的内容:
void setup() {
size(600, 800);
frameRate(7);
background(137, 156, 199);
} // Acaba void setup
void draw() {
// 随机线条粗细的三角形
noFill();
stroke(225, 225, 225);
strokeWeight(random(20)); // 粗细不正确地变化
triangle(580, 780, 580, 750, 500, 780);
}
请注意,我已经将代码中的英文部分翻译成了中文,如您所需。如果您有任何其他需要,请随时告诉我。
英文:
I'm trying to paint a triangle with a random stroke weight.The problem is that the stroke weight only changes if the new value is bigger than the older value. Here's what I've tried. I don't know if I am supposed to redraw or refresh the display at the bottom of the draw void.
void setup() {
size(600, 800);
frameRate(7);
background(137, 156, 199);
} // Acaba void setup
void draw() {
// RANDOM WEIGHT TRIANGLE
noFill();
stroke(225, 225, 225);
strokeWeight(random(20)); // DOESN'T CHANGE PROPERLY
triangle(580, 780, 580, 750, 500, 780);
}
答案1
得分: 3
图片并不会在每次draw()
方法循环时神奇地消失,这就是为什么你看不到三角形线条权重比之前低的情况。你需要重新绘制一切才能看出来。
这很好,因为这实际上很容易做到。将这一行代码 background(137, 156, 199);
移动到draw()
方法中,作为你所做的第一件事。在此之后,绘图应该会如你所期望地表现:
玩得开心!
英文:
The image isn't magically disappearing at every loop of the draw()
method, that's why you don't see when the triangle's line weight is lower than before. You would need to repaint everything for it to be obsious.
Which is nice, because it's really easy to do. Move this line background(137, 156, 199);
in the draw()
method as the first thing that you do. After this the drawing should behave as you expect:
Have fun!
答案2
得分: 2
background
不仅仅设置背景颜色,它实际上还会清除背景。您必须在每一帧中清除背景(在draw
中):
void draw(){
background(137, 156, 199);
// [...]
}
英文:
background
does not only set the background color, it actually clears the background. You have to clear the background in every frame (in draw
):
void draw(){
background(137, 156, 199);
// [...]
}
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论