Question about drawing origin & Translate

The one thing that’s been puzzling me about Codea is why the drawing origin (0,0) is in the bottom left hand corner of the screen. I read the drawing is based on the Processing language and I thought that might be it, but I started reading the Processing “Orange” book over the weekend and they start off with 0,0 in the top left the same way everyone else does it.

So my question is why is the origin in the bottom left? does it offer any advantages? (other than making it a pain to port code from other systems) and is it possible to use Translate (or some other method) to put it back in the top left?

.@TechDojo actually, there is no real standard in graphical APIs. And it can even be inconsistent on the same platform — for example, UIKit on iOS draws with the origin at the top left, and Core Graphics on iOS draws with the origin at the bottom left. Mac OS X uses the bottom left as well.

We chose bottom left for Codea because it made the most sense to us — x is from left-to-right, and y is from bottom-to-top.

You can flip and translate the coordinate system before drawing:

function draw()
    scale(1,-1)
    translate(0,-HEIGHT)

    -- draw
end

Unfortunately text() and images will appear flipped under this transformation.

@Simeon thanks for the heads up, I was unaware of how Core Graphics and OS X stored their origin, I’d just assumed they were the same as everything else.

Interesting little hack - I’ll have to try it out and see if makes a difference to me :slight_smile: