Problems rotating and scaling shapes

edited May 2017 in How To...

I created a shape by combining various primitives in a group. However the group's origin is in the top left of the group. There is no problem doing translations but rotation and scaling take place around the top left of the shape which (as far as I can figure) makes it difficult to rotate shapes around a more central point. Is there a way in Processing to redefine a shape's (or any other object's) local coordinates or apply a local transformation matrix?

Tagged:

Answers

  • You're so close it hurts. Just translate your shape (-shape.width/2,-shape.height/2):

    void setup(){
      size(400,400);
    }
    
    void draw(){
      background(0);
      translate(200,200);
      rotate(map(millis()%5000,0,5000,0,TWO_PI));
      translate(-20,-20);
      rect(0,0,40,40);
    }
    
  • edited May 2017

    Is there a way in Processing to redefine a shape's (or any other object's) local coordinates or apply a local transformation matrix?

    1. apply a local transformation matrix: https://processing.org/reference/translate_.html

      pushMatrix();
      translate(x,y);
      // draw under local transformation here
      popMatrix();
      
    2. redefine a shape's local coordinates: https://processing.org/reference/PShape_translate_.html (note -- persistent and cumulative!)

      PShape s = createShape();
      s.beginDraw();
      s.translate(x,y);
      s.endDraw();
      
Sign In or Register to comment.