Daily Creative Coding

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

星空

/**
* Starry Sky
*
* @author aa_debdeb
* @date 2016/01/01
*/

void setup(){
  size(500, 300);
  smooth();
  noLoop();
  background(30);
  colorMode(HSB, 360, 100, 100, 100);
  for(int i = 0; i < 200; i++){
    PVector pos = new PVector(random(width), random(height));
    float radious = map(pow(random(1), 3), 0, 1, 1, 5);
    boolean isBlue = random(1) < 0.5;
    new Star(pos, radious, isBlue).display();
  }   
}

class Star{
  
  PVector pos;
  float radious;
  boolean isBlue;
  
  Star(PVector pos, float radious, boolean isBlue){
    this.pos = pos;
    this.radious = radious;
    this.isBlue = isBlue;
  }
  
  void display(){
    noStroke();
    float hue = isBlue ? 270 : 160;
    for(float s = 1.0; s >= 0.0; s -= 0.01){
      float saturation = map(pow(s, 10), 0, 1, 0, 100);
      fill(hue, saturation, 100, 30);
      float r = map(s, 0, 1, 0, radious);
      ellipse(pos.x, pos.y, r, r);
    }
  }
  
}