読者です 読者をやめる 読者になる 読者になる

Daily Creative Coding

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

カラーパレット

/**
* color mosaic
* 
* @author aa_debdeb
* @date 2016/03/28
*/

void setup(){
  size(500, 500);
  noStroke();
  mousePressed();
}

void draw(){
  
}

void mousePressed(){
  float hcenter, hwidth, smin, smax, bmin, bmax;
  hcenter = random(360);
  hwidth = random(180);
  smin = random(100);
  smax = random(smin, 100);
  bmin = random(100);
  bmax = random(bmin, 100);
  
  colorMode(HSB, 360, 100, 100);
  for(int w = 0; w < width; w += 5){
    for(int h = 0; h < height; h += 5){
      float hue = map(random(1), 0, 1, hcenter - hwidth, hcenter + hwidth);
      if(hue > 360){
        hue -= 360;
      } else if(hue < 0){
        hue += 360;
      }
      float sat = map(random(1), 0 ,1, smin, smax);
      float bri = map(random(1), 0, 1, bmin, bmax);
      fill(hue, sat, bri);
      rect(w, h, 5, 5);
    }
  }
  
  colorMode(RGB, 255);
  fill(255);
  text("hue: " + str(int(hcenter - hwidth)) + " ~ " + str(int(hcenter + hwidth)), 10, 20);
  text("saturation: " + str(int(smin)) + " ~ " + str(int(smax)), 10, 40);
  text("brightness: " + str(int(bmin)) + " ~ " + str(int(bmax)), 10, 60);

}