Changing coordinate system without mirroring objects

I would love to change my coordinate to be in the middle instead. It’s easily done with translate(width/2, height/2). Like so:

def setup():
    size(1920, 1080)

def draw():
    background(255)
    translate(width/2,height/2)

I get:

But as you can see the y axis goes negative when going upwards… I would love to fix that.
I tried that by using scale(1,-1), but off course that flips fonts in the canvas…

Any ideas?

Hi,

Is it a problem is you just invert the y values each time you need to draw something on the screen?
I think it’s just a habit to take.

I suppose you could create a function for flipping the text, something like –

def displayCoord(x, y):
    pushMatrix()
    scale(1, -1)
    if x:
        text(x, x, 0)
    elif y:
        text(y, 0, y*-1)
    popMatrix()
    
translate(width/2, height/2)
scale(1, -1)

displayCoord(0, -20)
displayCoord(-30, 0)
displayCoord(28, 0)
displayCoord(0, 25)

Hello,

In my example I subtract all y values from height and fonts are fine.

This is a Processing JAVA version:

int x, y;

void setup() 
	{
  size(500, 300);
  textSize(24);
	}

void draw() 
	{
  background(255);
  
  x = 400;
  y = 200;
  
  line(0, height-0, x, height-y);
  
  fill(0);
  textAlign(CENTER, CENTER);
  text("T", x/2, height-y/2);
	}

:)

1 Like

Thank you everyone for your brilliant solutions! I already made myself a custom text function, so flipping as @tabreturn suggested was a solution that worked well for me.

I could get use to it @josephh I guess, but I plan on using p5 a lot so I would to make my life as easy as possible :smiley:

you guys are awesome.

2 Likes