Created
November 26, 2012 20:04
-
-
Save chrisallick/4150285 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Location[] points = new Location[20]; | |
int myX, myY, myZ; | |
int radius = 100; | |
void setup() { | |
size( 640, 640, P3D); | |
//frameRate(25); | |
createPoints(); | |
noFill(); | |
strokeWeight( 1 ); | |
smooth(); | |
} | |
void draw() { | |
background(110); | |
translate(width/2, height/2, 300); | |
float t = millis()/10000.0f; | |
rotateY(t); | |
//stroke( 0, 0, 0, 60 ); | |
stroke(149,248,168,20); | |
sphere( 90 ); | |
for(int i = 0; i <= points.length-1; i++) { | |
pushMatrix(); | |
translate(points[i].v.x, points[i].v.y, points[i].v.z); | |
noFill(); | |
stroke( points[i].c ); | |
sphere( points[i].r ); | |
popMatrix(); | |
points[i].update(); | |
} | |
stroke( 0 ); | |
//line( points[0].v.x, points[0].v.y, points[0].v.z, points[1].v.x, points[1].v.y, points[1].v.z ); | |
for( int i = 0; i < 19; i++ ) { | |
tracerArc( points[i].v, points[i+1].v ); | |
//tracerArc( points[1].v, points[2].v ); | |
} | |
} | |
public PVector comb(float a, PVector v1,float b, PVector v2) { | |
float rx =a* v1.x + b*v2.x; | |
float ry =a* v1.y + b*v2.y; | |
float rz =a* v1.z + b*v2.z; | |
return new PVector(rx,ry,rz); | |
} | |
//public void comb(float a,Vecteur v1,float b, Vecteur v2,float c,Vecteur v3) { | |
// float rx =a* v1.x + b*v2.x+c*v3.x; | |
// float ry =a* v1.y + b*v2.y+c*v3.y; | |
// float rz =a* v1.z + b*v2.z+c*v3.z; | |
// return new Vecteur(rx,ry,rz); | |
//} | |
public void tracerArc(PVector v1, PVector v2) { | |
PVector v = new PVector(); | |
PVector vLast = new PVector(); | |
float angle=(float)Math.acos(v2.dot(v1)/v2.dot(v2)); | |
for( float t=0; t<=1; t+=0.02f ) { | |
v = comb(sin((1-t)*angle)/sin(angle),v1,sin(t*angle)/sin(angle),v2); | |
if( t==0 ) { | |
line(v1.x, v1.y, v1.z, v.x, v.y, v.z); | |
} else { | |
line(vLast.x, vLast.y, vLast.z, v.x, v.y, v.z); | |
} | |
vLast = v; | |
} | |
line(vLast.x, vLast.y, vLast.z, v2.x, v2.y, v2.z); | |
} | |
void createPoints() { | |
for(int i = 0; i <= points.length-1; i++) { | |
float angleA = random(0, TWO_PI); | |
float angleB = random(0, TWO_PI); | |
myX = int(radius*sin(angleA)*cos(angleB)); | |
myY = int(radius*sin(angleA)*sin(angleB)); | |
myZ = int(radius*cos(angleA)); | |
points[i] = new Location (myX, myY, myZ, angleA, angleB, i); | |
} | |
} | |
void mouseMoved() { | |
for(int i = 0; i <= points.length-1; i++) { | |
points[i].test( mouseX, mouseY ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment