float fi=0; float x,y,z,r; int i,j,k; int NSEGMENTS=3000; int N=40; int M=18; void setup() { size(400, 400, P3D); colorMode(RGB,100); } void DrawKnot() { int i; float x,y,z,xl,yl,zl; float beta; float phi,theta; float r; float mx=(mouseX<=0?50:mouseX); float my=(mouseY<=0?200:mouseY)/100.0f; float distance=dist(200,200,mx,my); zl=yl=xl=-255; beginShape(LINES); for (i=0;i<=NSEGMENTS;i++) { beta = mx*i * PI / (float)NSEGMENTS; r = 1.2 * 0.6 * sin(0.5 * PI + 6 * beta); theta = 4 * beta*my; phi = 0.2 * PI * sin(6 * beta); x = r * cos(phi) * cos(theta); y = r * cos(phi) * sin(theta); z = r * sin(phi); stroke(0,beta*r,100,20); if (zl==-255) { xl=x; yl=y; zl=z; } vertex(xl,yl,zl); vertex(x,y,z); xl=x; yl=y; zl=z; } endShape(); } void draw() { background(0,0,0); translate(200,200); scale(300,300,300); DrawKnot(); }