Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

三角形の色のストリーム

/**
 * triangle color stream
 * 
 * @author aadebdeb
 * @date 2017/03/02
 */

function setup() {
  createCanvas(windowWidth, windowHeight);
  frameRate(5);
}

function draw() {
  background(64);
  var r = 150;
  var step = 50;
  var num = 10;
  var col = [
    color(201, 92, 157),
    color(50, 173, 198),
    color(170, 206, 54),
  ];
  translate(width / 2 - num * step / 2, height / 2);
  noStroke();
  for(var i = num; i >= 0; i--) {
    fill(col[(frameCount + i) % col.length]);
    beginShape();
    vertex(r * cos(-HALF_PI), r * sin(-HALF_PI));
    vertex(step * i + r * cos(-HALF_PI), r * sin(-HALF_PI));
    vertex(step * i + r * cos(-HALF_PI + TWO_PI / 3), r * sin(-HALF_PI + TWO_PI / 3));
    vertex(r * cos(-HALF_PI + TWO_PI / 3 * 2), r * sin(-HALF_PI + TWO_PI / 3 * 2));
    endShape(CLOSE);
  }
}
f:id:aa_debdeb:20170301234330j:plain