Daily Creative Coding

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

宇宙

/**
* Universe
*
* @author aa_debdeb
* @date 2016/01/07
*/

void setup(){
  size(640, 480);
  smooth();
  noLoop();
  background(30);
  colorMode(HSB, 360, 100, 100, 100);
  float noiseX = random(100);
  float noiseY = random(100);
  for(int i = 0; i < 2000; i++){
    PVector pos = new PVector(random(width), random(height));
    if(random(noise(pos.x * 0.01 + noiseX, pos.y * 0.01 + noiseY)) < 0.3){
      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;
    
    fill(270, 100, 100, 0.5);
    float lradious = map(radious, 1, 5, 30, 300);
    ellipse(pos.x, pos.y, lradious, lradious);
    
    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);
    }
  }
  
}