resizing sketch window behaving differently in Processing 3

stfstf
edited December 2015 in Questions about Code

Hello -

The following sketch runs correctly in processing 2x. When the sketch is resized, a new layout is calculated and displayed.

However, in Processing 3, the new layout is not recalculated when the screen is resized, and the display appears to be scaled.

If I allow the animation loop to run, then the sketch runs as desired.
But I need it to run with noLoop();

Can anyone shed light on this behavior difference between Processing 2 and 3?

Thanks a lot!

float HEIGHT,WIDTH;

//a point 2/3 across the screen
float DIVIS;

void setup(){

 size (320, 240);

 HEIGHT=height;WIDTH=width;

 println("in setup, width is "+WIDTH+" height is "+HEIGHT);


//for processing 3, uncommen
//surface.setResizable(true);
frame.setResizable(true);

 calculateSizing();

 noLoop();
}

void draw(){

  background(255); noFill();

  //recalculate on width or height delta. 
  if (WIDTH!=width || HEIGHT!=height) calculateSizing();

  rect(10, 10, WIDTH-20, HEIGHT-20);
   fill(0);
    text ("width is "+WIDTH+" height is "+HEIGHT,20,20);
    text("WIDTH/3*2",DIVIS,HEIGHT/2-20);
    ellipse(DIVIS,HEIGHT/2,10,10);

}

//width or height have changed, 
void calculateSizing(){

    //so reassign global variables new values
    WIDTH=width;HEIGHT=height;

    //and use to calc some new layout
    DIVIS=WIDTH/3*2;

    println("calculateSizing called: width="+WIDTH+" height="+HEIGHT);
}
Sign In or Register to comment.