# 三次元の線を重ねる

```/**
* 3D Lines
*
* @author aa_debdeb
* @date 2015/11/28
*/

float gray;
float theta1;
float theta2;

int grayStep;
float theta1Noise;
float theta2Noise;

void setup(){
size(500, 500, P3D);
background(255);
smooth();
frameRate(30);

theta1 = PI;
theta2 = PI;

grayStep = 1;
theta1Noise = random(100);
theta2Noise = random(100);
}

void draw(){

radious = 250 + map(noise(radiousNoise + frameCount * 0.01), 0, 1, -75, 75);
theta1 += map(noise(theta1Noise + frameCount * 0.01), 0, 1, -PI / 32, PI / 32);
theta2 += map(noise(theta2Noise + frameCount * 0.01), 0, 1, -PI / 32, PI / 32);

if(theta1 < 0){
theta1 += TWO_PI;
} else if(theta1 >= TWO_PI){
theta1 -= TWO_PI;
}
if(theta2 < 0){
theta2 += TWO_PI;
} else if(theta2 >= TWO_PI){
theta2 -= TWO_PI;
}

gray += grayStep;
if(gray < 0){
gray = 0;
grayStep *= -1;
} else if(gray > 255){
gray = 255;
grayStep *= -1;
}

float x1 = radious * sin(theta1) * cos(theta2);
float y1 = radious * sin(theta1) * sin(theta2);
float z1 = radious * cos(theta1) * cos(theta2);
float x2 = -x1;
float y2 = -y1;
float z2 = -z1;

stroke(gray);
translate(width/2, height/2);
line(x1, y1, z1, x2, y2, z2);
}
```