/** * Sphere */ float angle = 0.0; float rSize; // rectangle size float sRadius; // sphere radius Vector vnew, axis, mouse; Quaternion vq, rotq, rotqc, rotqf; Vector[] points, pointsNew; int N = 40; int transitionPos = 0; int transitionMax = 200; void setup() { size(640, 360, P3D); sRadius = min(width, height) / 4; rSize = width / 48; noStroke(); fill(204, 204); // Quaternion & vectors needed for rotation axis = new Vector(); mouse = new Vector (); vq = new Quaternion (); rotq = new Quaternion(); rotqc = new Quaternion(); rotqf = new Quaternion(); vnew = new Vector(); // Points randomly places then evenly distributed points = new Vector[N]; pointsNew = new Vector[N]; for(int i=0; i 0) { N--; updatePoints(); } } } void mouseMoved() { mouse.x = mouseX-width/2; mouse.y = mouseY-height/2; mouse.z =0; float l = mouse.length() / (2*sRadius); if (l > 0.5) { l = 1 - l; } if (l > 0.1) { l -= 0.1; angle = l / 10.0; axis.x = -mouse.y; axis.y = mouse.x; axis.z = mouse.z; axis.normalize(); computeRotation(); } else { angle = 0; } } void updatePoints() { // Copy current positions for (int i=0; i