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

30 min. Processing

毎日30分、Processingで何かを作る

線の帯

p5.js ランダム
/**
 * line belts
 * 
 * @author aadebdeb
 * @date 2017/02/25
 */
 

var posW = 0;
var posH = 0;
var posVW;
var posVH;
var posAW;
var posAH;
var numY = 50;
var intervalH;
var posAWOffset, posAHOffset;
var stColor;

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

function mousePressed() {
  background(255);
  initialize();
}

function initialize() {
  posW = 0;
  posVW = 5;
  posAW = random(-1, 1);
  posH = random(height);
  posAH = random(-1, 1);
  posVH = 0;
  numY = int(random(20, 30));
  intervalH = random(2, 6);
  posAWOffset = random(10000);
  posAHOffset = random(10000);
  stColor = [
    color(106, 129, 139),
    color(127, 165, 155),
    color(74, 87, 75),
  ][int(random(3))];
  stroke(stColor);
  
}

function draw() {
  var nposW = posW + posVW;
  var nposH = posH + posVH;
  for (var y = 0; y < numY; y++) {
    var h = posH + ((y + 1) - numY / 2) * intervalH;
    var nh = nposH + ((y + 1) - numY / 2) * intervalH;
    line(posW, h, nposW, nh);
  }

  posAW = map(noise(frameCount * 0.03 + posAWOffset), 0, 1, -0.2, 0.3);
  posAH = map(noise(frameCount * 0.02 + posAHOffset), 0, 1, -0.1, 0.1);  
  posVW += posAW;
  posVW = constrain(posVW, -5, 5);
  posVH += posAH;
  posVH = constrain(posVH, -2, 2);
  posW = nposW;
  posH = nposH;
  
  if (posW < 0 || posW > width || posH + (0 - numY / 2) * intervalH > height || posH + (numY - numY / 2) * intervalH < 0) {
    initialize();
  }
  
}
f:id:aa_debdeb:20170223093409j:plain