Please explain me the effect of redraw() / loop() / noloop() here

edited November 2017 in Questions about Code

Please explain me these cases:

1. If I run code below, the thick line is drawn after the 2nd click

2. If I remove noLoop(); , the thick line is drawn after the 1st click

3. If I remove loop(); , the thick line is not drawn, not matter how many clicks I perform

4. If I remove noLoop(); and loop();, the thick line is drawn after the 1st click

         boolean ready_for_thick_line = false; 

         void mousePressed() {
           drawLine(10);
           ready_for_thick_line = true;
           redraw();
         }

         void drawLine(int width) {
           strokeWeight(width);
           line(20, 20, 80, 20);
         }

         void draw() {
         if (ready_for_thick_line) 
         {
            loop();
         }
         else{
            drawLine(1);
            noLoop();
         }  
        }
Sign In or Register to comment.