Small Question about code that rotates a "shape"

edited July 2016 in How To...

I'm trying to make rotating polygon on processing, but I'm having a bit of trouble... The way the project will eventually work is that there will be an n-sided polygon, made out of lines, and the polygon rotates 360°. Right now, I'm just interested in having a single line be able to make a full rotation and change its angle as its rotating.

The line in the project works as intended (sort of), but I can't seem to increase the size of it without drastically increasing the speed

Any and all help is appreciated!



  • edited July 2016 Answer ✓

    could it be any solution for you?

    class movableLine{
      float vx, vy;
      float lineLen;
      float x1, y1;
      float angle, angleConst;
      movableLine(float x1, float y1, float lineLen, float angle)
        this.x1 = x1;
        this.y1 = y1;
        this.lineLen = lineLen;
        this.angle = angle;
        this.angleConst = angle;
      void display()
      void changeSpeeds()
        vx = 10* cos(angle);
        vy = 10 * sin(angle);
        angle += angleConst;
      void move()
        x1 += vx;
        y1 += vy;
    void setup()
      size(500, 500);
      background(255, 255, 255);
      color(0, 0, 0);
    movableLine oneLine = new movableLine(0., 0., 50, PI/32);
    void draw()
      background(255, 255,255  );
      translate(width/2, height/2);
  • edited July 2016

    This works incredibly well! Thank you very much!

    If you don't mind me asking... Why'd you change the display() method to have a push/popMatrix()? I'm having trouble understanding the translate(x1, y1) part, as well well as changing the move() method to only affect x1 and y1?

    Again, thank you very much for solving my question

Sign In or Register to comment.