Can't seem to understand why? Seems to me like the Class is declared, and structured properly? Am I missing something with the operators?
Code:
int NUM_LINES = 1000;
Line pline;
ParticleLines plines;
float radius = 100;
int cx, cy;
void setup(){
size(800,800,P3D);
float theta = random(0,TWO_PI);
float u = random(-1,1);
pline = new Line(theta,u);
plines = new ParticleLines();
stroke(random(255),random(255),random(255));
frameRate(30);
}
void draw(){
background(0);
camera(0,0,500,0,0,0,0,1,0);
pushMatrix();
rotateY(map(mouseX,0,width,0,TWO_PI));
rotateX(map(mouseY,0,height,0,TWO_PI));
plines.update();
plines.render();
popMatrix();
}
class ParticleLines {
Line[] lines = new Line[NUM_LINES];
void ParticleLines(){
for(int i=0; i<NUM_LINES; i++){
float theta = random(0,TWO_PI);
float u = random(-1,1);
lines[i] = new Line(theta, u);
}
}
void update(){
for(int i=0; i<NUM_LINES; i++){
lines[i].update();
}
}
void render(){
for(int i=0; i<NUM_LINES; i++){
lines[i].render();
}
}
}
class Line {
float theta, u;
float vtheta, vu;
float x,y,z;
void Line(float _theta, float _u) {
theta = _theta;
u = _u;
vtheta = 0;
vu = 0;
}
void update(){
vtheta += random(-0.001, 0.001);
theta += vtheta;
if(theta<0 || theta>TWO_PI) vtheta *= -1;
vu += random(-0.001, 0.001);
u += vu;
if(u<-1 || u>1) vu *= -1;
vu *= 0.95;
vtheta *= 0.95;
x = radius * cos(theta) * sqrt(1-(u*u));
y = radius * sin(theta) * sqrt(1-(u*u));
z = u*radius;
}
void render(){
pushMatrix();
//translate(width,y,z);
line(0,0,0,x,y,z);
popMatrix();
}
}