Display trouble

I’m rather new at Processing. It is different from the programing that I’m used to. I’m an old timer that found Arduino and Processing as something to do during retirement. Anyway, I wrote a short routine that should display a line then erase it and move it over a little. For some reason, sometimes the display window will show nothing, sometimes I’ll get the initial line then the last line, but never what I expect. There must be some kind of way to make the display refresh? Thanks Mike
<
void setup(){
size(600,600);
}

void draw(){
for (int i = 100; i<400; i=i+1){
line(i,200,300,400);
background(255);
delay(10);
}
}
/>

Hi @mike_z

So, there a few things to know.

  1. The draw() method is a loop that refreshes automatically your sketch window. So, you don’t need the for loop only the incrementing position of your line.
  2. Processing draws objects in order of appearance, i.e., the background should be called first, and then all the objects that you wish to appear.
  3. If you call the background only once in setup, the sketch will keep all objects (in your case all lines being drawn, here is an example:
int i = 0;
void setup(){
size(600,600);
background(255);
}

void draw(){
i++;
fill(0);
line(100,i,400,i);
}

So if you want the line to be refreshed, then you refresh the background at all frames, i.e., call it inside draw(), like this:


int i = 0;
void setup(){
size(600,600);
background(255);
}

void draw(){
background(255);

i++;
fill(0);
line(100,i,400,i);
}

I suggest to you some tutorials on processing that may help you in the future :slight_smile:

Helpful links

The coding train channel:
https://www.youtube.com/watch?v=2VLaIr5Ckbs&list=PLzJbM9-DyOZyMZzVda3HaWviHqfPiYN7e&ab_channel=TheCodingTrain

Processing tutorials:
https://processing.org/tutorials/

Processing examples:
https://processing.org/examples/

Best regards

1 Like

Thanks for the reply. WHile I was gone, I think I figured out that the display doesn’t refresh until the end of the DRAW function. My problem was that I was using a FOR/NEXT loop and the program stayed in that loop and the end of the DRAW was not gotten to until the FOR/NEXT was over. AND I also palyed with the background and found what you are talking about.
So… what you did was a FOR/NEXT by using the DRAW repeating method. Learn something every day. Thanks