We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi guys, I am having a trouble to setup the correct rotation to some rectangle to make them draw a perfect circle.
I want them to be oriented in the center of the circle. I think it's just about the rotation, I tried many ways. But couldn't figure out how to do it. Here is how looks like my code.
import hype.*;
HDrawablePool pool;
float radius = 250;
float lineWithSpace = 20.0;
int numLines = round(TWO_PI * radius / lineWithSpace);
float angle = TWO_PI / numLines;
float radiusAdjust = (numLines * lineWithSpace)/ TWO_PI;
void setup() {
size(800,800);
H.init(this).background(255);
smooth();
pool = new HDrawablePool(numLines);
pool.autoAddToStage();
for (float p = 0 ; p < numLines; ++p) {
HRect d = new HRect(1, 70);
pool.add(d);
}
pool.onCreate(
new HCallback() {
public void run(Object obj) {
int i = pool.currentIndex();
for (float p = 0 ; p < pool.count(); p++) {
pushMatrix();
HDrawable d = (HDrawable) obj;
float myAngle = p*angle;
float x = radiusAdjust*cos(myAngle);
float y = radiusAdjust*sin(myAngle);
d.loc(x,y);
d.rotate(radians(45 + i));
popMatrix();
}
}
}
)
.requestAll()
;
}
void draw() {
translate(width/2, height/2);
H.drawStage();
}