We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello! I am making a project that involves a lots of shapes and then animating some of them. Awhile i was trying to make this one square with a circle inside rotate, I ran into multiple problems. This are the objects that I am trying to rotate (that are, of course, in void draw() ):
fill(237, 26, 55);
rect(336, 605, 112, 121);
fill(255);
ellipse(392, 662, 63, 63);
So, firstly I tried using only rotate(PI/2) before that, but it just disappeared. Then I tried translate, in case that was what was missing, but once again nothing. I thought that maybe rectMode(CENTER) would finally make everything work, but it actually made everything move out of place! I tried putting everything between push and pop matrix but it didn't work. I don't understand what is happening or what I am doing wrong. And the thing is that I moved these objects to the end of the code so it wouldn't interfere with the rest. I searched everywhere but I cannot find anything to help me. Thank you for your time.
Answers
I'm not really sure what you're asking. Can you please post a MCVE instead of a disconnected snippet of code?
Hi! So this is the original (with bits of it deleted so there is not too much code on the screen):
then what i did was move what i wanted to the end and added rotate:
which made the rect disappear.
Then I tried to use translate before that..
And then I tried to use rectMode(CENTER) and push/popMatrix but the rect mode only made things worse and the push/pop didn't do anything
what I am trying to do is make it spin around it's center, but I can't find anything to help me with my problems.
Thank you, I hope this helps you understand my problem better!
Have a look Examples from Transformation.
And my sample code:
Thank you for answering. I tried to see if it could help, but I couldn't find a way to. I just wanted a simple (it doesn't seem that simple anymore :S) rotation motion. Is there any way to isolate rectMode(CENTER); to a single part of the code?
You wrote:
The answer is the usage of pushMatrix and popMatrix as demonstrated below.
Rotating the Correct Way
The correct way to rotate the square is to:
rectMode(CENTER);
).see
https://www.processing.org/tutorials/transform2d/
Example
Here is an example.
Key elements:
usage of
rectMode(CENTER);
translate() command before rotate() command
call
rect()
with 0,0 as position (which is the origin of the coordinate system / Matrix)pushMatrix and popMatrix isolate their section against the rest of the code: Note that the blue box is not rotating
Here is the code:
Hello! Yes, it was exactly that that I wanted to do! I ended up not using rectMode and just adjusting the rect coordinates to the translate, but the rest helped me so much! Thank you very much!