xxxxxxxxxx
float r;
//n is quality, m is amount of spirals
int n=150, m=12;
//k is worm speed coefficient
float k=4;
//d is turn degree
float d;
//df is length of worm, w is weight, mW is max weight
float df=PI/8, w=10, mW=10;
void setup(){
size(640, 640,OPENGL);
colorMode(HSB,PI,2,1);
noFill();
//stroke(0,0,1);
strokeWeight(w);
r=width/3;
frameRate(30);
}
void draw(){
background(0);
translate(width/2,height/2,0);
rotateX(-PI/6);
float tX=0, tY=r, tZ=0;
beginShape();
curveVertex(0,r,0);
for (int i=0; i<=n; i++){
float degree=map(i,0,n,0,PI);
float x=0,y=r,z=0;
float tx=x;
float dd=d%(PI*k)/k;
if (abs(degDiff(degree*2,dd*2)/2)<df) {
stroke(degree,cos(map(degDiff(degree*2,dd*2)/2,-df,df,-PI,PI))+1,1);
//strokeWeight(w+mW*(cos(map(degDiff(degree*2,dd*2)/2,-df,df,-PI,PI))+1));
strokeWeight(2*w);
} else {
stroke(0,0,1);
strokeWeight(w);
}
x=x*cos(degree)+y*sin(degree);
y=y*cos(degree)-tx*sin(degree);
degree=map(i,0,n,0,TWO_PI*m)+d;
tx=x;
x=x*cos(degree)+z*sin(degree);
z=z*cos(degree)-tx*sin(degree);
//line(tX,tY,tZ,x,y,z);
curveVertex(x,y,z);
//vertex(x,y,z);
tX=x; tY=y; tZ=z;
}
curveVertex(0,-r,0);
endShape();
d+=.07;
}
float degDiff(float deg1, float deg2){
float d1=deg1%TWO_PI, d2=deg2%TWO_PI;
if (abs(d1-d2)>PI) {
return min(d1,d2)+TWO_PI-max(d1,d2);
} else {
return d1-d2;
}
}