Last active
December 30, 2015 12:18
-
-
Save sasaki-shigeo/7827853 to your computer and use it in GitHub Desktop.
Drawing hexagons in Processing /
Processing で正6角形を描く
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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