Daily Creative Coding

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

3Dフラッシュ

/**
* flash in 3D
* 
* @author aa_debdeb
* @date 2016/04/15
*/

ArrayList<PVector> points;
float bg;

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

void mousePressed(){
  points = new ArrayList<PVector>();
  for(int i = 0; i < 200; i++){
    float x = random(width);
    float y = random(height);
    float z = random(-100, 250);
    points.add(new PVector(x, y, z));
  }
  float hue = random(360);
  colorMode(HSB, 360, 100, 100);
  fill(hue, 100, 100);
  bg = hue < 180 ? hue + 180: hue - 180;
}

void draw(){
  background(bg, 100, 100);
  if(frameCount % 2 != 0){lights();} 
  for(PVector p: points){
    pushMatrix();
    translate(p.x, p.y, p.z);
    sphere(10);
    popMatrix();
  }
}