Why does x start woth 0 and y with 1 and why is the height always 1 pixel less.

I asked something before but I can't find it.

Let's say I have size(500, 500);

With processing, the mouseX goes from 0 to 499. But mouseY goes from 1 to 499.

This makes the height 499 instead of 500!

Or was this an OSX thing?

Answers

  • If you access the pixell array of your sketch directly, y starts from 0. Otherwise you will not be able to change the first row of pixels in your sketch. Accessing pixels this way is done using two for loops (for clarity).

    With mouseX and mouseY, I like to believe if you try really carefully then you should be able to get mouseY to display zero.

    void setup(){size(200,200);} 
    void draw(){background(0);text("Here "+mouseX+"\n            "+mouseY,mouseX,mouseY);}
    

    Kf

  • I have had mouseY as 0 before, it requires careful timing.

  • it might be an osx thing. here's my attempt on linux. you'll notice that the mouse is well into the toolbar at this point. same happens with x.

    xy

    (this might just be a function of where the hotspot of the cursor is defined to be, but it looks a bit odd)

  • edited February 2017

    The cursor hotspot is not always the top left pixel of the cursor image. For instance the CROSS cursor has the hotspot in the centre of the cursor image. WIth the arrow I suggest that it is probably the top left white pixel position.

    BTW on OSX I couldn't get mousey = 0 either.

  • I got it on Windows 8.1.

  • Yeah it seems like an OSX bug.

  • But that's more likely to be a problem with OSX than with Processing, so problem solved.

  • How does that solve a problem :)

    =))

    It doesn't happen in P3D so it is a software render bug.

  • It doesn't? Then you're right. I didn't know that.

Sign In or Register to comment.