jonobr1 / two.js

A renderer agnostic two-dimensional drawing api for the web.
https://two.js.org
MIT License
8.27k stars 454 forks source link

How can you rotate a Two.js object around a pivot/anchor point? #689

Closed Jamzy01 closed 1 year ago

Jamzy01 commented 1 year ago

How can I rotate a Two.js object around a pivot/anchor point?

How exactly can I rotate and scale any two js object around a pivot point? For example, If I want to rotate a shape by pivoting around the top left corner or from any point on the shape, how can I do that? Here is an example of what I want to do:

image

jonobr1 commented 1 year ago

Here's a demo to show how you can change the orientation of an object: https://codepen.io/jonobr1/pen/OJwrjrJ

Jamzy01 commented 1 year ago

That's an interesting approach to rotating an object from a pivot point, but I think it will be fairly easy to implement.

jonobr1 commented 1 year ago

Also, if you're using only Two.Rectangle there is Two.Rectangle.origin which is a Two.Vector that represents an amount to offset all verts.

No other object has this property though.