The screen is updating after while loop is completed ? need help

here a example using a millis timer:

long startT, stopT=1000;
float ang = 0;
float colc;
color rf;

void setup() {
  size(500, 500);
  colc=random(255);
  rf=color(colc, 0, 255-colc);
}

void myTimer() {
  if ( millis() > startT + stopT ) {
    startT = millis();
    println("_next loop_");
    // what else you need to be done now?
    ang++;
    colc=random(255);
    rf=color(colc, 0, 255-colc);
  }
} 

void draw() {
  background(255, 244, 206);  
  myTimer();
  translate(width/2, height/2);
  rotate(ang *TWO_PI/60.0);
  draw_object();
}

void draw_object() {
  stroke(0, 0, 200);
  line(0, 0, 50, 50);
  fill(rf);
  rect( 50, 50, 20, 20);
}

1 Like