日常の進捗

主に自分のための,行為とその習慣化の記録

三角形を円周上に配置する

はじめは、特に何も考えないでプログラムした。円周状に何か並べたいなと思ったので三角形を配置した。三角形の頂点が伸び縮みしたらどうだろうと考えた。次に半径の異なる円を複数描画して敷き詰めようとしてみた。円ごとに頂点の伸び縮みする周期をずらしたり、大きさを変えてみることにした。

float r = 250;
float step = 20;
void setup() {
  size(960, 540);
  colorMode(HSB, 360, 100, 100, 100);
}

void draw() {
  background(0, 0, 0);
  for (float r = 0; r < 250; r += 30) {
    pushMatrix();
    translate(width/2, height/2);
    rotate(r/10);
    for (float angle = 0; angle < 360; angle += step) {
      float theta = radians(angle);
      float thetaN = radians(angle+step/4);
      float thetaM = radians(angle-step/4);
      float x2 = cos(thetaN) * r;
      float y2 = sin(thetaN) * r;
      float x3= cos(thetaM) * r;
      float y3= sin(thetaM) * r;

      float xa = cos(theta) * (r+sin(r/10 + theta + frameCount*0.03)*r/5);
      float ya = sin(theta) * (r+sin(r/10 + theta + frameCount*0.03)*r/5);

      float xb = cos(theta) * (r+sin(r/10 + theta + PI+frameCount*0.03)*r/5);
      float yb = sin(theta) * (r+sin(r/10 + theta + PI+frameCount*0.03)*r/5);
      
      noStroke();
      fill((r+angle*5)%360, 80, 100);
      beginShape();
      vertex(xa, ya);
      vertex(x2, y2);
      vertex(x3, y3);
      endShape(CLOSE);
      fill((r+angle*5+180)%360, 80, 100);
      beginShape();
      vertex(xb, yb);
      vertex(x2, y2);
      vertex(x3, y3);
      endShape(CLOSE);
    }
    popMatrix();
  }
}