読者です 読者をやめる 読者になる 読者になる

Daily Creative Coding

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

ベジエ曲線で雫の形をつくる

/*
 * bezier drops
 *
 * @author aadebdeb
 * @date 2017/02/07
 */

var rgb;
var type = 0;

function setup() {
  createCanvas(windowWidth, windowHeight);
  frameRate(30);
  noStroke();
  rgb = [
    color(255, 0, 0),
    color(0, 255, 0),
    color(0, 0, 255)
  ];
}

function mousePressed() {
  if (type == 0) {
    type = 1;
  } else {
    type = 0;
  }
}

function draw() {
  blendMode(BLEND);
  if (type == 0) {
    background(0);
    blendMode(SCREEN);
  } else {
    background(255);
    blendMode(EXCLUSION);
  }
  for (var w = -100; w <= width + 100; w += 100) {
    for (var h = -100; h <= height + 100; h += 100) {
      push();
      translate(w, h);
      for(var ci = 0; ci < 3; ci++) {
        drawBezier(w, h, ci);
      }
      pop();
    }
  }
}

function drawBezier(w, h, ci) {
  fill(rgb[ci]);
  stroke(rgb[ci]);
  var nv = w * 0.01 + h * 0.02 + ci * 0.03 + frameCount * 0.035;
  var size = 100;
  var anchor = createVector(map(noise(nv, 0), 0, 1, -size, size), map(noise(nv, 1), 0, 1, -size, size));
  var control1 = createVector(map(noise(nv, 2), 0, 1, -size, size), map(noise(nv, 3), 0, 1, -size, size));
  var control2 = createVector(map(noise(nv, 4), 0, 1, -size, size), map(noise(nv, 5), 0, 1, -size, size));
  bezier(
    anchor.x, anchor.y,
    control1.x, control1.y,
    control2.x, control2.y,
    anchor.x, anchor.y
  );
}
f:id:aa_debdeb:20170204161103j:plain