// Body in a box // Humble beginnings of a "volume" library ? // Licensed under Creative Commons, W:Blut 2009, Vanhoutte Frederik // http://creativecommons.org/licenses/by/2.0/be/deed.en // // Disclaimer: the software // // This Processing sketch is free code and provided without any warranty. // It is free for any use. It represents some amateur coding by the author. // It is not intended to have any instructional value nor does it represent good coding practice. int numPoints=20; //number of points in the container int currentSelection=0; // simple arrays to store the properties of the points PVector[] points=new PVector[numPoints];// PVector[] vels=new PVector[numPoints]; // coordinates of the containervertices float[][] containerVertices; // simple face array for the container. Each subarray contains the indices of the vertices. int[][] containerFaces; float bufferMouseX, bufferMouseY; //half-edge mesh, one for each voronoi cell HE_Mesh[] voronoiCells=new HE_Mesh[numPoints]; //representation of a plane, used to cut the mesh Plane P=new Plane(new PVector(0,0,0),new PVector(0,1,0)); //size of box int S=700; void setup(){ size(800,540,P3D); background(255); //smooth(); //hint(ENABLE_OPENGL_4X_SMOOTH); initializePoints(); buildContainer(); buildVoronoi(); } void draw(){ drawVoronoiBox(); updatePoints(); buildVoronoi(); } void initializePoints(){ for (int i=0;iS){ points[i].x=2*S-points[i].x; vels[i].x*=-1; } if(points[i].y>S){ points[i].y=2*S-points[i].y; vels[i].y*=-1; } if(points[i].z>S){ points[i].z=2*S-points[i].z; vels[i].z*=-1; } } } void mouseClicked(){ initializePoints(); buildVoronoi(); } void keyPressed(){ currentSelection++; if(currentSelection==numPoints) currentSelection=0; }