Setting size of display window to a percentage of screen size

I’m trying to make a program where users input values and the program spits out a final value through an equation.

This is all pretty simple, but the one thing I can’t seem to figure out is display window sizing.

My display is 4k, so if I were to size the window a reasonable size for a 1080p screen, say 1000x1000 pixels, it would be tiny and unreadable for me and other 4k users.

A workaround I thought I found for this was sizing the window as half of the screen size using:

size(displayWidth*1>>2,displayHeight*1>>2);

but this spits out the error for only using numbers rather than variables for the size command.

This also means using integers at the beginning of the code to calculate a fraction of the screen size won’t work, ie.:

int sizeX = displayWidth*1>>2;
int sizeY = displayHeight*1>>2;

size(sizeX,sizeY);

Would there be any workaround for this or am I cursed to have to either change my screen resolution every time I run the program or run the program at fullscreen?

Thanks in advance.

size() usage is quite limited: It can be used only once and it requires explicit values, no variables. So you need to think a bit differently. You can use displayWidth to test display size and based on that set size like this.

void settings() {
  if (displayWidth > 2000) {
    size(2000,2000);
  } else if(displayWidth < 1000) {
    size(500,500);
  } else {
    size(1000,1000);
  }
  
}
1 Like