> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.l81kABrBpPz/rev.515
 * 
 * authors: 
 *   wilsnat

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



float dx = 200;
float dy = 200;
float dc = 1000;
float alpha = 0.3;
float beta = 0.2;
float bx;
float by;
float bdifx = 0.0; 
float bdify = 0.0; 
float cos_alpha = cos(alpha);
float sin_alpha = sin(alpha);
float cos_beta = cos(beta);
float sin_beta = sin(beta);

//the following arrays are a simple copy/paste from previous code
float[] lines = { -100,-100,100,-100,-100,-100,1,255,255,255,-100,100,-100,-100,-100,-100,1,255,255,255,-100,100,100,-100,-100,100,1,255,255,255,-100,100,100,-100,100,-100,1,255,255,255,100,-100,-100,-100,-100,-100,1,255,255,255,100,-100,100,-100,-100,100,1,255,255,255,100,-100,100,100,-100,-100,1,255,255,255,100,100,-100,-100,100,-100,1,255,255,255,100,100,-100,100,-100,-100,1,255,255,255,100,100,100,-100,100,100,1,255,255,255,100,100,100,100,-100,100,1,255,255,255,100,100,100,100,100,-100,1,255,255,255 };
float[] spheres = {};
float[] triangles = {};

void rot(x,y,z,p) {
   float x1=cos_alpha*x-sin_alpha*z;
   float y1=y;
   float z1=sin_alpha*x+cos_alpha*z;
   float x2=x1;
   float y2=cos_beta*y1-sin_beta*z1;
   float z2=sin_beta*y1+cos_beta*z1;
   p[0]=x2/(1.0+z2/dc)+dx;
   p[1]=y2/(1.0+z2/dc)+dy;
}


void setup() {
  size(400, 400);
  stroke(255);
  smooth();
  noLoop();
  drawnow();
}


void drawnow() {
  float[] pa={0,0};
  float[] pb={0,0};
  float[] pc={0,0};
  background(0);
  fill(80);
  for(var i=0; i<lines.length; i+=10) {
     rot(lines[i+0],lines[i+1],lines[i+2],pa);
     rot(lines[i+3],lines[i+4],lines[i+5],pb);
     strokeWeight(1);
     stroke(lines[i+7],lines[i+8],lines[i+9]);
     line(pa[0],pa[1],pb[0],pb[1]);
  }
  for(var i=0; i<spheres.length; i+=7) {
    noStroke();
     fill(spheres[i+4],spheres[i+5],spheres[i+6],90);
     rot(spheres[i+0],spheres[i+1],spheres[i+2],pa);
     ellipse(pa[0],pa[1],spheres[i+3],spheres[i+3]);
  }
  for(var i=0; i<triangles.length; i+=12) {
     noStroke();
     fill(triangles[i+9],triangles[i+10],triangles[i+11],90);
     rot(triangles[i+0],triangles[i+1],triangles[i+2],pa);
     rot(triangles[i+3],triangles[i+4],triangles[i+5],pb);
     rot(triangles[i+6],triangles[i+7],triangles[i+8],pc);
     beginShape();
     vertex(pa[0], pa[1]);
     vertex(pb[0], pb[1]);
     vertex(pc[0], pc[1]);
     endShape();
  }
}


void mousePressed() {
  bdifx = mouseX-bx; 
  bdify = mouseY-by;
}


void mouseDragged() {
  bx = mouseX-bdifx; 
  by = mouseY-bdify; 
  alpha = 0.01*bx;
  beta = 0.01*by;           
  cos_alpha=cos(alpha);
  sin_alpha=sin(alpha);
  cos_beta=cos(beta);
  sin_beta=sin(beta);      
  drawnow()      
}