Skip to content

Instantly share code, notes, and snippets.

@sasaki-shigeo
Last active December 30, 2015 12:18
Show Gist options
  • Save sasaki-shigeo/7827853 to your computer and use it in GitHub Desktop.
Save sasaki-shigeo/7827853 to your computer and use it in GitHub Desktop.
Drawing hexagons in Processing / Processing で正6角形を描く
void setup() {
size(500, 500);
for (int i = 0; i < 20; i++) {
hexagon(random(width), random(height), 20);
}
}
/** drawing a hexagon inscribed a circle as radius r and its center is placed at (x, y).
*/
void hexagon(float x, float y, float r) {
pushMatrix();
translate(x, y);
scale(1, -1);
rotate(HALF_PI);
beginShape();
for (int i = 0; i < 6; i++) {
vertex(r * cos(TWO_PI * i / 6), r * sin(TWO_PI * i / 6));
}
endShape(CLOSE);
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment