Daily Creative Coding

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

二重の輪

/**
 * double ring
 * 
 * @author aadebdeb
 * @date 2017/03/01
 */


function setup() {
  createCanvas(windowWidth, windowHeight);
  noStroke();
}

function draw() {
  background(247, 248, 218);
  translate(width / 2, height / 2);
  var num = 20;
  var angStep = TWO_PI / num;
  var timeScale = 0.008;
  noFill();
  fill(200, 51, 122);
  for (var i = 0; i < num; i++) {
    var r = 150;
    var ang = angStep * i;
    ellipse(r * cos(ang), r * sin(ang), 13, 13);
  }
  fill(255);
  noStroke();
  for (var i = 0; i < num; i++) {
    var ang = angStep * i;
    var r = map(cos(ang * num / 2 + frameCount * timeScale * 5 + HALF_PI / 2), -1, 1, 100, 200);
    var size = map(cos(ang * num / 2 + frameCount * timeScale * 10), -1, 1, 3, 20);
    ellipse(r * cos(ang + frameCount * timeScale), r * sin(ang + frameCount * timeScale), size, size);
  }
}
f:id:aa_debdeb:20170227224204j:plain