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

Daily Creative Coding

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

createGraphics()でグリッチっぽくする

/*
 * chaotic replications
 *
 * @author aadebdeb
 * @date 2017/02/06
 */

var canvas;

function setup() {
  canvas = createCanvas(windowWidth, windowHeight);
  frameRate(30);
  colorMode(HSB, 360, 100, 100);
  noStroke();
  background(0, 0, 100);
}

function draw() {
  var hue = random(360);
  var sat = random(30, 100);
  var bri = 100
  fill(hue, sat, bri);
  var d = random(50, 100);
  ellipse(random(width), random(height), d, d);
  
  var divNum = pow(2, int(random(1, 8)));
  var wSize = width / divNum;
  var hSize = height / divNum;
  var w = wSize * int(random(divNum));
  var h = hSize * int(random(divNum));
  if (random(1) < 0.94) {
    image(canvas, w, h, wSize, hSize);
  } else {
    fill(0, 0, 100);
    rect(w, h, wSize, hSize);
  }
}
f:id:aa_debdeb:20170202235713j:plain