How to rotate object around edge?

I have this code right here that rotates a rectangle.

    pushMatrix();
    translate(xpos + 20, ypos - 10);
    rotate(radians(swing));
    rect(0, 0, 7, 35);
    popMatrix();

    swing += 1;

But when I run the code, the rectangle rotates around the center, but I want it to rotate around the edge. How do I achieve this effect?

1 Like

Your code is translating and then rotating in that order… what if?

:)

2 Likes

I see now! Thanks you

1 Like

Hello cybernet, try this code, you might wanna hard code the translate arguments & change these two zeros that are inside the rect() into also some hard coded argument, here is my code;

push();
  translate(200, 200);
  rotate(radians(x-159));
  rect(200, 0, 7, 35);
  pop();
 
  
  x = x + 3;

i hope that helps

1 Like

You very welcome, glad that i can help :wink: