Daily Creative Coding

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

レーザービーム

/**
* Laser Beam
*
* @author aa_debdeb
* @date 2015/11/19
*/

float[] startXs;
float[] startYs;

void setup(){
  size(500, 500);
  smooth();
  frameRate(45);
  startXs = new float[4];
  startYs = new float[4];
  for(int i = 0; i < 4; i++){
    startXs[i] = random(100);
    startYs[i] = random(100);
  }
  
  background(0);
}

void draw(){
  noStroke();
  fill(0, 5);
  rect(-1, -1, width, height);
  
  stroke(0, 255, 0, 100);
  strokeWeight(1);
  float noiseStep = frameCount * 0.01;
  line(50, 50,  50 + map(noise(startXs[0] + noiseStep), 0, 1, 0, 400), 50 + map(noise(startYs[0] + noiseStep), 0, 1, 0, 400));
  line(50, height - 50, 50 + map(noise(startXs[1] + noiseStep), 0, 1, 0, 400), 50 + map(noise(startYs[1] + noiseStep), 0, 1, 0, 400));
  line(width - 50, 50, 50 + map(noise(startXs[2] + noiseStep), 0, 1, 0, 400), 50 + map(noise(startYs[2] + noiseStep), 0, 1, 0, 400));
  line(width - 50, height - 50, 50 + map(noise(startXs[3] + noiseStep), 0, 1, 0, 400), 50 + map(noise(startYs[3] + noiseStep), 0, 1, 0, 400));
  
}