-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please make current x and y available after translate and rotate. #1873
Comments
We currently have no access to the current transform matrix being applied to the canvas. It is an experimental feature that may get added to the HTML5Canvas spec, but it's not implemented across browsers yet: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/currentTransform To maintain a copy of the matrix ourselves within p5.js and update as transforms are applied would be possible, but it would significantly slow performance. For now, you might try using a library like this one: https://github.com/leeoniya/transformation-matrix-js/blob/master/readme.md. It wraps the canvas transform method and keeps track of the matrix, and allows you to apply it to (x,y) coords which I think is what you're trying to do. |
I see. |
I found a nice solution:
https://www.reddit.com/r/p5js/comments/jo7ucf/clicking_on_a_translated_scaled_and_rotated_shape/ |
Translate, rotate and scale are really helpful in drawing.
But, in mousePressed, the current coordinate is not available.
That is, the current translated and rotated, coordinate.
At least, I have not found it.
Error message: Uncaught ReferenceError: x is not defined
Example:
Four circles in the corners of a 20 degrees tilted square.
Above Coffeescript transpiled to Javascript, so everybody can understand:
The text was updated successfully, but these errors were encountered: