Draw immediately non possibile in loop?

edited November 2017 in How To...

If I have a loop in draw function it's not possible draw, i can see a new draw only when loop DRAW beginning again. How it's possible draw immediately example text() or line()? ( Inside a for cycle or while)

Tagged:

Answers

  • https://forum.processing.org/two/discussion/8087/what-are-setup-and-draw

    screen is only updated when draw() finishes. so keep it short.

  • Ok I understand, it's possible create a some like subroutine or background task ?

  • show us what you have.

  • You are asking a question about specific kinds of solution without ever explaining what your problem is. I suspect that we could give you a better solution if you explained your problem is. You may be struggling with the idea that draw is a loop.

    Here is a sketch that is drawn all at once:

    void draw() {
      for (int i=0; i<height; i+=4) { // loop, counter, increment, end check
        line(0, i, width, i);
      }
    }
    

    Now we put the counter outside the draw loop, iterate inside the draw loop, and perhaps add a special condition for ending. Each time draw is called, it draws a line.

    int i=0; // counter
    void setup(){
      frameRate(2);
    }
    void draw() { // loop
      line(0, i, width, i);
      i+=4; // increment
      if(i>=height){ // end check
        noLoop();
      }
    }
    
Sign In or Register to comment.