# Distribute objects around a circle with a custom anchor point

I would like to distribute rectangles with a custom anchor point around a circle, they should change the angle based on the location on the circle.

I have bit of code that draws one rectangle, but i am unclear where to put the loop, or if i am going the wrong way about this.

``````glPushMatrix();
glTranslatef(1280 / 2, 720 / 2, 0); // Put in the middle of the canvas
glPushMatrix();
ofSetColor(255,255,255);
ofFill();
ofCircle(0,0,250);
glPushMatrix();
glRotatef(45, 0, 0, 1);  //Rotation around anchor point
ofSetColor(0,255,0);
ofFill();
glTranslatef(-50, -25, 0); //Translate to center of Rectangle
ofRect(0, 0, 100, 50);
glPopMatrix();
glPopMatrix();
glPopMatrix();``````

OK made some progress, i am now able to set the number of objects around the circle, added also ofxUI so i can see it visually. Now the last step i have to take is where to add the rotation about the rectangle anchor point.

Current Code:

``````glPushMatrix();
glTranslatef(ofGetWidth() / 2, ofGetHeight() / 2, 0); // Put in the middle of the canvas
ofSetColor(255,255,255);
ofFill();
for (int i = 0; i < numClones; i++) {
glPushMatrix();
glRotatef((360.0f/numClones)*i, 0, 0, 1);  //Rotation
ofSetColor(250, 0, 0);
ofFill();
glTranslatef(-50, -50, 0); //Translate to center of Rectangle
ofSetColor(0, 255, 0);
ofNoFill();
glPopMatrix();
}
glPopMatrix();``````

OK i got it, after experimenting :), it does now what it should do.
Here is the code:

``````glPushMatrix(); // Canvas Matrix
glTranslatef(ofGetWidth() / 2, ofGetHeight() / 2, 0);
glRotatef(rotCenter, 0, 0, 1);
for (int i = 0; i < numClones; i++) {
glRotatef((circleDegree * 1.0f) / numClones, 0, 0, 1);
glPushMatrix(); //Move Rectange Matrix
// Rectangle Matrix
glPushMatrix();
ofFill();
ofCircle(0, 0, 10);
ofNoFill();
glRotatef(cloneRot, 0, 0, 1);
ofRect(-cloneWidth / 2, -cloneHeight / 2, 0, cloneWidth, cloneHeight);
glPopMatrix();
glPopMatrix();
}
glPopMatrix();
``````

If someone is interested here is the final project compiled for windows.
http://www.quantumlaser.us/of/