How to put circles on each corner of a hexagon?

edited December 2013 in How To...

I need to know how to put a circle of each corner of an object. I need 6 circles per object (hexagon). I created the hexagon with a polygon "polygon(0, 0, 50, 6)". The object (hexagon) should rotate against clockwise, no matter what speed and the circles should rotate with the hexagon on its 6 corners. I can't find any solution, so I need help.

The Hexagon-Code:

pushMatrix(); translate(430, 480); rotate(frameCount / -100.0); polygon(0, 0, 50, 6); popMatrix();

Answers

  • Answer ✓
    PVector[] p = new PVector[6];
    
    void setup() {
      size(600, 600);
      noFill();
      for (int i = 0; i < 6; i++) p[i] = new PVector();
    }
    
    void draw() {
      background(255);
      translate(width/2, height/2);
      rotate(radians(frameCount));
    
      // Set the points based on theta with a radius of 100
      float theta = 0.0;
      for (int i = 0; i < 6; i++) {
        theta += TWO_PI/6.0;
        p[i].x = cos(theta)*100;
        p[i].y = sin(theta)*100;
      }
    
      // Draw the hexagon using the points
      for (int i = 0; i < 5; i++) {
        int nextPoint = i+1;
        line(p[i].x, p[i].y, p[nextPoint].x, p[nextPoint].y);
      }
      line(p[0].x, p[0].y, p[5].x, p[5].y);
    
      // Draw the circles using the points
      for (int i = 0; i < 6; i++) ellipse(p[i].x, p[i].y, 50, 50);
    }
    
Sign In or Register to comment.