Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Problem to draw a perfect circle with some rectangle.

$
0
0

Hi guys, I am having a trouble to setup the correct rotation to some rectangle to make them draw a perfect circle. I think it's just about the rotation. 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();
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles