processing-examples icon indicating copy to clipboard operation
processing-examples copied to clipboard

Add an example for the windowRatio() method

Open SableRaf opened this issue 3 years ago • 1 comments

The windowRatio() method and its associated variables rwidth, rheight, rmouseX, rmouseY are demonstrated in the release notes for Processing 4.0 beta 7 with the code below but we don't yet have an example built-in.

void setup() {
  windowResizable(true);
  windowRatio(1280, 720);

  cursor(CROSS);
  strokeWeight(10);
}

void draw() {
  background(240);
  fill(255);
  rect(0, 0, rwidth, rheight);

  fill(0);
  textAlign(CENTER, CENTER);
  textSize(200);
  text(rmouseX + ", " + rmouseY, rwidth/2, rheight/2);
}

SableRaf avatar Sep 24 '22 09:09 SableRaf

Yeah, and that one is more of a “testing” thing that I was using to demonstrate what was going on.

Also need to note in the (eventual) documentation that it works for most things or at least lots of things, but there are definitely exceptions.

For instance, the sketch that Dan was using on Coding Train this week was like a perfect example of the worst kind of code to adapt this way. :) Not only is it 3D, which can be funky to get right, it also sets up its own camera/project using ortho(), which would need special care as well.

benfry avatar Sep 25 '22 20:09 benfry