Daily Creative Coding

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

カラフル・タワー

/**
* colorful towers
*
* @author aa_debdeb
* @date 2016/09/29
*/

float rectSize = 20;
float hue;
float h;

void setup(){
  size(640, 640);
  colorMode(HSB, 360, 100, 100);
  background(0, 0, 100); 
  stroke(0, 0, 0);
  strokeWeight(1);
  h = 50; 
}

void mousePressed(){
  background(0, 0,100);
  h = 50;
}

void draw(){
  if(random(1) < 0.1){
    float hue = map(int(random(30)), 0, 30, 0, 360);
    float sat = 100;
    float w = random(width); 
    translate(w, h);
    
    fill(hue, sat, 100);
    beginShape();
    vertex(rectSize, 0);
    vertex(0, rectSize / sqrt(2));
    vertex(-rectSize, 0);
    vertex(0, -rectSize / sqrt(2));
    endShape(CLOSE);
  
    fill(hue, sat, 80);
    beginShape();
    vertex(0, rectSize / sqrt(2));
    vertex(0, rectSize / sqrt(2) + width);
    vertex(-rectSize, rectSize / sqrt(2) + width);
    vertex(-rectSize, 0);
    endShape(CLOSE);
    
    fill(hue, sat, 40);
    beginShape();
    vertex(0, rectSize / sqrt(2));
    vertex(rectSize, 0);
    vertex(rectSize, rectSize / sqrt(2) + width);
    vertex(0, rectSize / sqrt(2) + width);
    endShape(CLOSE);
  
  }
  h += 0.3;  
}
f:id:aa_debdeb:20160924144953j:plain