Skip to content

Instantly share code, notes, and snippets.

@sasaki-shigeo
Last active March 11, 2019 04:57
Show Gist options
  • Save sasaki-shigeo/7827243 to your computer and use it in GitHub Desktop.
Save sasaki-shigeo/7827243 to your computer and use it in GitHub Desktop.
drawing a pentagon in Processing / Processing で正5角形を描く
void setup() {
size(500, 500);
fill(255, 255, 0); // YELLOW
pentagon(250, 250, 100);
}
/** drawing a pantagon inscribed a circle as radius r ans its center is placed at (x, y).
*/
void pentagon(float x, float y, float r) {
pushMatrix();
translate(x, y);
scale(1, -1);
rotate(HALF_PI);
beginShape();
for (int i = 0; i < 5; i++) {
vertex(r * cos(TWO_PI * i / 5), r * sin(TWO_PI * i / 5));
}
endShape(CLOSE);
popMatrix();
}
@sasaki-shigeo
Copy link
Author

Processing で5角形を描く

点 (x, y) を中心とする半径 r の円に内接する正5角形を描く

  • 座標変換が pentagon メソッドの中に閉じるように pushMatrix() ... popMatrix() する。
  • 半径 r の円周上の 0°, 72°, 144°, 216°, 288° の点を結べば正5角形になる
  • 中心が (x, y) になるように,平行移動 (x, y)
  • 回転が反時計回りになるように,y軸のスケールを -1 倍
  • 開始点が上方向になるように 90° 回転

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment