Aspect ratio screen resizing

Hey, I’m really struggling aspect ratio on processing, i want to be able to resize the screen and when i resize it the object inside is also resized according to the screen. I have currently used:

surface.setResizable(true);
surface.setLocation(90, 90);
(can also use scale(); or would that be wrong)
This does allow me to change my screen but only o a certain limit and the object remains the same.
Can someone please guide me through, as to what am i doing wrong.

Thank you.

Hello,

An example that uses scale() in proportion to screen size():

float iniWidth = 300; 
float iniHeight = 300;

void setup() 
  {
  size(300, 300);
  surface.setTitle("Hello World!");
  surface.setResizable(true);
  surface.setLocation(100, 100);
  }

void draw() 
  {
  background(204);
  scale(width/iniWidth, height/iniHeight);
  strokeWeight(2);
  rectMode(CENTER);
  rect(150, 150, 50, 50);
  line(0, 0, 300, 300);
  line(300, 0, 0, 300); 
  }

:)

1 Like

within the context of p5.js - I am trying to digest the process of maintaining the aspect ratio of an image when resizing the window. Is it possible to position and scale images based on percentages??