Random stroke weight is always bigger in draw() – Processing

Tags: ,



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);
}

Answer

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:

Triangles!

Have fun!



Source: stackoverflow