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

Daily Creative Coding

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

パーリンノイズの層

/*
 * layers of perlin noise
 *
 * @author aadebdeb
 * @date 2017/01/30
 */

var colors;

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

function mousePressed() {
  
  var cscale = [random(0.1), random(0.1), random(0.1)];
  var coffset = [random(10000), random(10000), random(10000)];
  colorMode(HSB, 360, 100, 100);
  colors = [];
  for (var i = 0; i < 30; i++) {
    var h = random(360);
    var s = map(pow(random(1), 4), 0, 1, 0, 100);
    var b = constrain(randomGaussian(20, 5), 0, 100);
    colors.push(color(h, s, b));
  }
  
  var nscale = createVector(random(0.02, 0.04), random(0.02, 0.04));
  var noffset = createVector(random(10000), random(10000));
  for (var w = 0; w < width; w++) {
    for (var h = 0; h < height; h++) {
      var n = noise(w * nscale.x + noffset.x, h * nscale.y + noffset.y);
      n = mapToQuad(n);
      stroke(colors[int(n * colors.length)]);
      point(w, h);
    }
  }  
  filter(BLUR, 1);
}

function mapToQuad(v) {
  if (v < 0.5) {
    return 2.0 * v * v;
  } else {
    return -2.0 * (v - 1.0) * (v - 1.0) + 1.0;
  }
}

function draw() {

}
f:id:aa_debdeb:20170129110603j:plain