Daily Creative Coding

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

スノーフォールライト

/**
* Snowfall Lights
* 
* @author aa_debdeb
* @date 2015/01/09
*/

ArrayList<Flow> flows;

void setup(){
  size(500, 500);
  smooth();
  frameRate(30);
  background(0);
  
  flows = new ArrayList();
  for(int i = 0; i < 100; i++){
    flows.add(new Flow());
  }
}

void draw(){
  noStroke();
  fill(0, 64);
  rect(0, 0, width, height); 
  for(Flow flow : flows){
    flow.display();
  }
}

class Flow{

  PVector start;
  float len, current;
  
  Flow(){
    float x = random(width);
    float y = map(random(1), 0, 1, 0, height - 150);
    start = new PVector(x, y);
    len = map(random(1), 0, 1, 100, 200);
    current = random(len);
  }
  
  void display(){
    float next = current + 5;
    stroke(0, 0, 255);
    strokeWeight(4);
    line(start.x, start.y + current + 0.5, start.x, start.y + next + 0.5);
    stroke(255);
    strokeWeight(2);
    line(start.x, start.y + current, start.x, start.y + next);
    if(next > len){
      current = 0;
    } else {
      current = next;
    }
    
  }
  
}