Daily Creative Coding

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

filter(BLUR)で霞んでいく線

/**
 * blurred line
 *
 * @author aadebdeb
 * @date 2017/02/28
 */

var c1, c2, cl, clv;
var tx, ty, vx, vy;

function setup() {
  createCanvas(300, 300);
  frameRate(3);
  strokeWeight(1);
  initialize();
}

function mousePressed() {
  initialize();
}

function initialize() {
  tx = random(TWO_PI);
  ty = random(TWO_PI);
  vx = random(PI / 64, PI / 32) * (random(1) < 0.5? 1: -1);
  vy = random(PI / 64, PI / 32) * (random(1) < 0.5? 1: -1);
  c1 = getColor();
  c2 = getColor();
  cl = 0;
  clv = 0.03;
  background(255);
}

function draw() {
  translate(width / 2, height / 2);
  var ntx = tx + vx;
  var nty = ty + vy;
  strokeWeight(1);
  stroke(lerpColor(c1, c2, cl));
  line(120 * sin(tx), 120 * sin(ty), 120 * sin(ntx), 120 * sin(nty));
  filter(BLUR, 1);
  tx = ntx;
  ty = nty;
  cl += clv;
  if (cl > 1.0) {
    c1 = c2;
    c2 = getColor();
    cl -= 1.0;
  }
}

function getColor() {
  colorMode(HSB, 360, 100, 100);
  var c = color(random(360), random(40, 100), 100);
  colorMode(RGB, 255, 255, 255);
  return color(red(c), green(c), blue(c));
}
f:id:aa_debdeb:20170226120706j:plain