Daily Creative Coding

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

サーチライト

/**
* searchlight 
*
* @author aa_debdeb
* @date 2016/09/03
*/

ArrayList<Point> points;
float rot = 0;

void setup(){
  size(500, 500);
  noStroke();
  points = new ArrayList<Point>();
  for(int i = 0; i < 5000; i++){
    points.add(new Point());
  }
}

void draw(){
  background(0);
  translate(width / 2, height / 2);
  for(Point p: points){
    p.display();
  }
  rot += PI / 128;
  if(rot >= TWO_PI){
    rot -= TWO_PI;
  }
}

class Point{
  
  float angle;
  float radious;
  
  Point(){
    angle = random(TWO_PI);
    radious = map(sqrt(random(1)), 0, 1, 0, 200);
  }
  
  void display(){
    float d = min(abs(angle - rot), TWO_PI - abs(angle - rot));
    float alpha = map(d, 0, PI / 2, 255, 0);
    fill(0, 255, 255, alpha);
    ellipse(radious * cos(angle), radious * sin(angle), 2, 2);
  }
}
f:id:aa_debdeb:20160829234432j:plain