随机的笔触粗细在draw()函数中始终较大 – Processing

huangapple go评论70阅读模式
英文:

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()方法中,作为你所做的第一件事。在此之后,绘图应该会如你所期望地表现:

随机的笔触粗细在draw()函数中始终较大 – Processing

玩得开心!

英文:

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:

随机的笔触粗细在draw()函数中始终较大 – Processing

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>



huangapple
  • 本文由 发表于 2020年10月6日 22:57:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/64228430.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定