nannou-org / nannou

A Creative Coding Framework for Rust.
https://nannou.cc/
6.01k stars 303 forks source link

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

Open SMUsamaShah opened 3 years ago

SMUsamaShah commented 3 years ago

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);
MacTuitui commented 3 years ago

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.

SMUsamaShah commented 3 years ago

Didn't know I could do this.

mitchmindtree commented 3 years ago

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.