lucy2911
YaBB Newbies
Offline
Posts: 5
Lee Byron's library Modification
May 31st , 2010, 4:56am
Hello, I am very new to Processing (and Scripting / Java in general)... Currently, I am trying to modify the Lee Byron's Mesh to make the points move. I managed to make them move, but now I would like to make the points that are closer to each other faster. I also tried to add new points (saw the code in discourse) but it did not work) I could use PVector to find distances between points and than have them move faster over time but I am not sure how to go about it. (its the last part in this code) . sorry if it looks messy- my code is divided into tabs and im not sure (yet) how to display this in discourse forums.. Here is the code: (divided in 3 tabs): MeshLibDemo: ____________________________________ import megamu.mesh.*; void setup() { size(1100,700); // initialize points and calculate diagrams initMesh(); smooth(); } void draw() { background(200); drawMesh(); initMesh(); //movePoints(); moveFaster(); } void keyPressed() { // reset points and mesh when spacebar is pressed if(key==' ') { initPoints(); initMesh(); } // use keys '1'-'3' to toggle display if(key=='1') showVoronoi=!showVoronoi; if(key=='2') showDelaunay=!showDelaunay; if(key=='3') showHull=!showHull; } void mouseMoved() { if(myRegions==null) return; points[0][0]=mouseX; points[0][1]=mouseY; initMesh(); } //adding new points: //void mousePressed() { // float [][] tmp=new float [1][2]; // tmp [0][0]=mouseX; // tmp [0][1] = mouseY; // points [0] = tmp [0]; // redraw(); //}[/color] ________________ Mesh Tab: Voronoi myVoronoi; Delaunay myDelaunay; Hull myHull; float[][] myEdges; MPolygon myRegions[],myHullRegion; int col[]; float startX,startY,endX,endY; float[][] regionCoordinates; boolean showVoronoi=true; boolean showDelaunay=false; boolean showHull=false; void drawMesh(){ if(myRegions==null) return; if(showVoronoi) { strokeWeight(1); stroke(0); for(int i=1; i<myRegions.length; i++) { fill(col[i]); regionCoordinates = myRegions[i].getCoords(); myRegions[i].draw(this); // draw this shape } } // draw Voronoi as lines if(showDelaunay) { strokeWeight(2); stroke(255,0,0); for(int i=0; i<myEdges.length; i++) { startX = myEdges[i][0]; startY = myEdges[i][1]; endX = myEdges[i][2]; endY = myEdges[i][3]; line(startX, startY, endX, endY); } } // draw Hull in semi-transparent yellow if(showHull) { strokeWeight(1); stroke(0); fill(255,255,0, 150); myHullRegion.draw(this); } } void initMesh() { if(points==null) initPoints(); int oldlength=0; if(myRegions!=null) oldlength=myRegions.length; myVoronoi = new Voronoi( points ); myHull = new Hull( points ); myDelaunay = new Delaunay( points ); myRegions = myVoronoi.getRegions(); myHullRegion = myHull.getRegion(); myEdges = myDelaunay.getEdges(); if(oldlength!=myRegions.length) { col=new int[myRegions.length]; for(int i=0; i<myRegions.length; i++) { float prob=random(100); if(prob>60) col[i]=color(random(30,100)); else col[i]=color(random(200,255)); } col[0]=color(255,0,0); } } _______ particles tab: float[][] points; float[][] vel; int searchDist; PVector v1, v2; //xPosition = points; //yPosition = points; void initPoints() { points = new float[100][2]; vel = new float[100][2]; for(int i=0; i<points.length; i++) { points[i][0] = random(width); // first point, x points[i][1] = random(height); // first point, y } for(int i=0; i<vel.length; i++) { vel[i][0] = random(-2,2); // first point, x vel[i][1] = random(-2,2); // first point, y } } void movePoints(){ for(int i=0; i<points.length; i++) { points[i][0] +=vel[i][0]; // first point, x points[i][1] +=vel[i][1]; // first point, y } } //move particles in smaller regions faster - over time- this is where i //get lost: void moveFaster(PVector v1, PVector v2){ PVector v1 = new PVector (random (100)); PVector v2 = new PVector (random (100,200)); } }