《Processing 番外編》 制作例

Processing 制作例 (描画)

ハート

int HART = 4; 

void setup() {
  size(200, 200);
  background(255);
}

void draw() {
  background(255);
  fill(241,10,86);
  noStroke();
  pushMatrix();
  translate(width/2, height/2);
  beginShape();
  for (int theta = 0; theta < 360; theta++) {
    float x = HART * (16 * sin(radians(theta)) * sin(radians(theta)) * sin(radians(theta)));
    float y = (-1) * HART * (13 * cos(radians(theta)) - 5 * cos(radians(2 * theta)) 
      - 2 * cos(radians(3 * theta)) - cos(radians(4 * theta)));

    vertex(x, y);
  }
  endShape(CLOSE);
  popMatrix();
}


星型

int vertex_num = 5*2; //頂点数(星を描画、頂点の数*2)
int S; //中心から頂点までの距離(半径)
int S_out = 70; //中心から頂点までの距離(半径)
int S_in = S_out/2; //中心から谷までの距離(半径)

void setup() {
  size(200, 200);
  background(255);
}

void draw() {
  background(255);
  fill(255,228,0);
  noStroke();
  pushMatrix();
  translate(width/2, height/2);
  rotate(radians(-90));
  beginShape();
  for (int i = 0; i < vertex_num; i++) {
    if (i%2 == 0) {
      S = S_out;
    } else {
      S = S_in;
    }
    vertex(S*cos(radians(360*i/vertex_num)), S*sin(radians(360*i/vertex_num)));
  }
  endShape(CLOSE);
  popMatrix();
}


自分メモ用。随時更新予定。