Daily Creative Coding

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

絡み取られた球

f:id:aa_debdeb:20160119105356j:plain
/**
* Entwined Sphere
*
* @author aa_debdeb
* @date 2016/01/21
*/

float radious = 150;

void setup(){
  size(500, 500, P3D);
  smooth();
  sphereDetail(16);

  background(0);
  translate(width / 2, height / 2);
  float px = radious * sin(0) * cos(0);
  float py = radious * cos(0);
  float pz = radious * sin(0) * sin(0);
  for(float i = 0; i <= 1.0; i += 0.001){
    float rad1 = map(i, 0, 1, 0, PI);
    float rad2 = map(i, 0, 1, 0, TWO_PI * 10);
    float x = radious * sin(rad1) * cos(rad2);
    float y = radious * cos(rad1);
    float z = radious * sin(rad1) * sin(rad2);
    for(float c = 0.05; c <= 1.0; c += 0.05){
      stroke(map(pow(c, 2), 0, 1, 255, 30), map(pow(c, 2), 0, 1, 255, 144), map(pow(c, 2), 0, 1, 255, 255), 10);
      strokeWeight(map(c, 0, 1, 0, 10));
      line(x, y, z, px, py, pz);
    }
    px = x;
    py = y;
    pz = z;
  }

  noStroke();
  for(float i = 0; i <= 1.0; i += 0.005){
    pushMatrix();
    float rad1 = map(i, 0, 1, 0, PI);
    float rad2 = map(i, 0, 1, 0, TWO_PI * 10);
    float x = radious * sin(rad1) * cos(rad2);
    float y = radious * cos(rad1);
    float z = radious * sin(rad1) * sin(rad2);
    translate(x, y, z);
    float sphereSize = map(sin(map(i, 0, 1, 0, TWO_PI * 10)), -1, 1, 3, 6);
    for(float c = 0.02; c <= 1.0; c += 0.02){
      fill(map(pow(c, 2), 0, 1, 255, 30), map(pow(c, 2), 0, 1, 255, 144), map(pow(c, 2), 0, 1, 255, 255), 10);
      sphere(map(c, 0, 1, 0, sphereSize));
    }
    popMatrix();
  }
}