We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I am currently writing a spirograph, that is, I have some arms stringed together, the first arm rotates around the middle of the screen, the next one rotates around the extremity of the first and so on.
The simplest way for me to get to the various points of the spirograph is to rotate() the context by the angle of the arm, then translate() by its length, and doing this iteratively, the new origin (0,0) is the point at the end of the last arm. The problem here is that I'd like to know the coordinates of this point relative to the default context (i.e. the one p5 uses when actually drawing that point to the canvas) so that I can save the various points in an array, so that I can draw the spirograph as a shape instead of drawing a bunch of individual points, which only looks like a continuous line if I draw a lot of them, and prevents me from clearing the screen between frames since I don't have those points saved anywhere to redraw them.
If I understand correctly, all translate() and rotate do is affect the transformation matrix, and when a drawing function is called, like point() or rect() or vertex() is used, it applies the transformation matrix to the coordinates it received, and draws between the calculated points on the canvas. What I want is to have is that calculated point.
Is there any way to get these coordinates directly with a function of p5? If not, is there a way for me to access the transformation matrix and apply it to (0,0) manually, or would I need write a custom structure to keep track of current position and orientation, then use that to calculate the position of the current origin in the default context?
Thanks!