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

Daily Creative Coding

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

上から落ちてくる糸

/**
 * fall from ceiling
 * 
 * @author aadebdeb
 * @date 2017/03/11
 */

var offset;
var shows;
var actionFrames = 15;
var counter = 0;

function setup() {
  createCanvas(windowWidth, windowHeight);
  frameRate(60);
  offset = random(10000);
  event= false;
}

function draw() {
  background(0);
  noStroke();
  fill(255);
  var r = 100;
  ellipse(width / 2, height / 2, r * 2, r * 2);
  drawLines();
  
  var d = sqrt(sq(mouseX - width / 2) + sq(mouseY - height / 2));
  if (!shows && d < r) {
    showLines();
  }
  
  if (shows && d > r) {
    hideLines();
  }
  
  update();
}

function showLines() {
  shows = true;
  
}

function hideLines() {
  shows = false;
}

function update() {
  if(shows && counter != actionFrames) {
    counter++;
  } 
  if(!shows && counter != 0) {
    counter--;
  }
}

function drawLines() {
  stroke(255);
  strokeWeight(10);
  for(var w = 0; w <= width; w += 25) {
    var h = map(noise(w * 0.1 + offset), 0, 1, height / 10, height * 9 / 10) * map(counter, 0, actionFrames, 0, 1);
    line(w, -20, w, h - 20);
  }
}
f:id:aa_debdeb:20170308215811j:plain