Daily Creative Coding

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

金の玉

f:id:aa_debdeb:20160503184311j:plain
/**
* golden balls
*
* @author aa_debdeb
* @date 2016/05/05
*/

ArrayList<PVector> points;

void setup(){
  size(500, 500, P3D);
  points = new ArrayList<PVector>();
  while(points.size() < 500){
    float radious = random(200);
    float radian1 = random(PI);
    float radian2 = random(TWO_PI);
    float x = radious * sin(radian1) * cos(radian2);
    float y = radious * cos(radian1);
    float z = radious * sin(radian1) * sin(radian2);
    PVector point = new PVector(x, y, z);
    boolean isOver = false;
    for(PVector p: points){
      if(PVector.dist(p, point) < 20){
        isOver = true;
        break;
      }
    }
    if(!isOver){
      points.add(point);
    }
  }
  
  noStroke();
  fill(218, 165, 32);
}

void draw(){
  background(0);
  ambientLight(128, 128, 128);
  lightSpecular(255, 255, 255);
  directionalLight(128, 128, 128, 0, 0, -1);
  lightFalloff(1, 0, 0);
  shininess(7);
  translate(width / 2, height / 2);
  for(PVector p: points){
    pushMatrix();
    translate(p.x, p.y, p.z);
    sphere(10);
    popMatrix();
  }
}