Loading...
Logo
Processing Forum

Move window origin to lower left

in General Discussion  •  Other  •  1 year ago  
Hello.

I find it very awkward that the origin of positions start at top left and increases bottom-rightward.

Is there any coordinate-command to change this to a more conventional coordinate system? With the origin placed in the most bottom left pixel of the window for example with x increasing to the right and y increasing to the top?

It would help much, changes in orientation and signals from equations to the program makes everything more difficult...

Thanks.

Replies(3)

It's not that simple to change the coordinate origin of an entire platform. You can, however, manipulate the matrix:

Copy code
  1. void setup() {
  2.   //setup() code
  3. }

  4. void draw() (
  5.   scale(1, -1);
  6.   translate(0, -height);
  7.  
  8.   //draw() code
  9. }

Of course, it isn't always that easy; this will only apply to drawing. When you want to get, say, the mouse location, or use the pixels array, this will still have the origin in the top-left corner. To avoid confusion, it is probably best to simply adapt to using the top-left system.
Ok, that helped, thanks calsign, that was fast :)
Beware though that the solution above will also flip any text or images upside down. If you stick with it and need to display text, you could add a method like the following that is called in place of text().

void rText(String txt, float xPos, float yPos)
{
  pushMatrix();
  translate(xPos,yPos);
  scale(1,-1);
  text(txt,0,0);
  popMatrix();
}

Should be easy to create the equivalent for images.