xxxxxxxxxx
final float r = 120;
float colorShade;
int N;
Line[] lines;
Boolean displaySphere = true;
PVector rotation = new PVector(0, 0);
PVector rotationSpeed = new PVector(0, 0);
void setup() {
size(400, 400, P3D);
colorMode(HSB, 1);
noFill();
initialize();
}
void draw() {
background(0);
noFill();
translate(width/2, height/2);
PVector dm = new PVector(pmouseY - mouseY, pmouseX - mouseX);
dm.mult(.001);
rotationSpeed.add(dm);
rotationSpeed.mult(.94);
rotation.add(rotationSpeed);
rotateX(rotation.x);
rotateY(rotation.y);
noFill();
for(int i = 0; i < N; i ++){
lines[i].display();
}
if(displaySphere){
fill(.015, .2, .2);
noStroke();
sphere(.99*r);
}
}
void mousePressed(){
initialize();
}
void keyPressed(){
displaySphere = !displaySphere;
}
void initialize(){
N = ceil(random(15));
colorShade = random(.9);
lines = new Line[N];
for(int i = 0; i < N; i ++){
lines[i] = new Line();
}
}
class Line {
int nb = 200;
PVector root = new PVector(random(123), random(123));
final float s = random(.02, .06);//.05
ArrayList<PVector> angles = new ArrayList<PVector>();
ArrayList<PVector> shift = new ArrayList<PVector>();
PVector speed = new PVector(random(-s, s), random(-s, s));
float a = random(123);
float b = random(123);
color col = color(random(colorShade, colorShade + .1), random(.7, 1), random(.7, 1));
final PVector rot = new PVector(random(123), random(123));
Line() {
for (int i = 0; i < nb; i ++) {
root.add(speed);
// a += TWO_PI * (noise(root.x) - .5) / 10;
// b += TWO_PI * (noise(root.y) - .5) / 10;
float prevA = a;
a += 2 * asin(sqrt(map(noise(root.x), .2, .8, 0, 1))) / 30;
b += PI * map(noise(root.y), .2, .8, -1, 1) / 30;
// if (Float.isNaN(a)) a = prevA;
if (a == NaN) a = prevA;
angles.add(new PVector(a, b));
shift.add(new PVector(0, 0, 0));
}
}
void display() {
rotateX(rot.x);
rotateY(rot.y);
stroke(col);
float x, y, z, u, t;
beginShape();
for (int i = 0; i < nb; i ++) {
u = angles.get(i).x += noise(root.x + i/1)/1500;
t = angles.get(i).y += noise(root.y + i/1)/1500;
x = r * sin(u) * cos(t);
y = r * sin(u) * sin(t);
z = r * cos(u);
vertex(x, y, z);
}
endShape();
root.add(speed);
// a += TWO_PI * (noise(root.x) - .5) / 10;
// b += TWO_PI * (noise(root.y) - .5) / 10;
float prevA = a;
a += 2 * asin(sqrt(map(noise(root.x), .2, .8, 0, 1))) / 30;
b += PI * map(noise(root.y), .2, .8, -1, 1) / 30;
angles.remove(0);
shift.remove(0);
angles.add(new PVector(a, b));
shift.add(new PVector(0, 0, 0));
// if (Float.isNaN(a)) a = prevA;
if (a == NaN) a = prevA;
}
}