日記帳

プログラミングのことをつぶやく日記です。

Processing で星を作る

Processing で星を作る

f:id:leokun0210:20200523224452p:plain

上記のような星をProcessingで描画します。Processingは初心者です。

コード

size(60, 60);
background(255);
noStroke();
fill(152, 251, 152);
int b;

int a[] = {1,4,2,5,3};

beginShape();
for (int i = 0; i < 5; i++) {
  b = a[i] - 1;
  float x = 30 * cos(2 * PI * b / 5 + PI / 2) + 30;
  float y = 30 * sin(2 * PI * b / 5 - PI / 2) + 30;
  vertex(x, y);
}
endShape();

Y軸は、下に行くほど増加するので、正負を逆にして考える必要があります。

参考

Drawing stars / Processing で星形(5芒星)を描く