flipping lines in 3D
in
Programming Questions
•
2 years ago
Hi
Playing with spheres and stumbled onto this. The answer doesn't really matter, but why do the lines flip over?
string
- //original from matt pearson's genart
import processing.opengl.*; - int radius = 150;
float betaInc = PI/10;
float gammaInc = PI/360; - void setup()
{
size(400, 400, OPENGL);
background(255);
frameRate(12);
} - void draw()
{
background(255);
translate(width / 2, height / 2, 0);
rotateX(frameCount * 0.04);
rotateY(frameCount * 0.03);
rotateZ(frameCount * 0.01);
float beta = 0;
float gamma = 0;
float lastx = 0;
float lasty = 0;
float lastz = 0;
while(gamma < PI)
{
beta += betaInc;
gamma += gammaInc;
float thisx = radius * cos(beta) * sin(gamma);
float thisy = radius * sin(beta) * sin(gamma);
float thisz = radius * cos(gamma);
strokeWeight(sin(gamma) * radius / 5);
float colourVal = map(thisz, -radius, radius, 0, 255);
stroke(colourVal, colourVal / 2, 255 - colourVal); - if(lastx != 0)
{
line(lastx, lasty, lastz, thisx, thisy, thisz);
}
beta += betaInc;
gamma += gammaInc;
float nextx = radius * cos(beta) * sin(gamma);
float nexty = radius * sin(beta) * sin(gamma);
float nextz = radius * cos(gamma); - lastx = nextx;
lasty = nexty;
lastz = nextz;
}
}
1