Daily Creative Coding

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

線のジャングル

/**
* abstract jungle
*
* @author aa_debdeb
* @date 2016/09/23
*/

PVector loc;
PVector vel;
float theta;
float len;
int lineStep;
color c;

void setup(){
  size(500, 500);
  background(143, 188, 143);  
  strokeWeight(2);
  setMover();
}

void mousePressed(){
  background(143, 188, 143);  
}

void setMover(){
  int state = int(random(4));
  float velSize = 10;
  float velAng = 0;
  switch(state){
    case 0:
      loc = new PVector(random(width), 0);
      velAng = random(0, PI);
      break;
    case 1:
      loc = new PVector(width, random(height));
      velAng = random(HALF_PI, HALF_PI * 3);
      break;
    case 2:
      loc = new PVector(random(width), height);
      velAng = random(PI, TWO_PI);
      break;
    case 3:
      loc = new PVector(0, random(height));
      velAng = random(HALF_PI * 3, HALF_PI * 5);
      break;
  }
  vel = new PVector(velSize * cos(velAng), velSize * sin(velAng));
  theta = random(PI);
  len = random(5, 20);
  c = color(random(140, 255), random(0, 140), random(0, 140));
}

void draw(){
  stroke(c);
  pushMatrix();
  translate(loc.x, loc.y);
  rotate(theta);
  line(-len, 0, len, 0);
  popMatrix();
  vel.rotate(random(-PI / 16, PI / 16));
  loc.add(vel); 
  if(loc.x < 0 || width < loc.x || loc.y < 0 || height < loc.y){
    setMover();
  }
}
f:id:aa_debdeb:20160920010258j:plain