nannou icon indicating copy to clipboard operation
nannou copied to clipboard

How to set origin to lower left corner instead of center?

Open SMUsamaShah opened this issue 3 years ago • 3 comments

I have a huge list of coordinates describing different shapes and lines. But they all assume left corner as the 0,0 position. Is there a way to set origin to lower left corner? so that when drawing shapes or lines or anything I don't have to translate each shape and just draw normally.

e.g. this should draw the rectangle in lower left corner of the window after moving the origin there.

draw.rect().color(STEELBLUE).w(10).h(10).x_y(0,0);

SMUsamaShah avatar May 09 '21 03:05 SMUsamaShah

You can translate the whole draw once then all the following calls will be translated.

draw = draw.x_y(-width*0.5, -height*0.5);

Now if you want a coordinate system like processing, you'll also have to invert the y axis, with scale.

MacTuitui avatar May 11 '21 06:05 MacTuitui

Didn't know I could do this.

SMUsamaShah avatar May 14 '21 01:05 SMUsamaShah

I recommend checking out the Window Coordinates tutorial in the guide too - hopefully it can give some tips for working comfortably with nannou's default coordinate system.

mitchmindtree avatar May 22 '21 14:05 mitchmindtree