//***************************************************************************** // VST: Graph editor and vertex spanning tree, Jarek Rossignac, March 2006 //***************************************************************************** int vn =5; // initial number of vertices int en =5; // initial number of edges int cap=128; // max nuber of edges and vertices pt[] P = new pt [cap]; // points (also called vertices or graph nodes) edge[] E = new edge[cap]; // edges int [] colEdge = new int[cap]; // colors of edges int [] colVert = new int[cap]; // colors of points pt Mouse = new pt(0,0); // current mouse position int bs=-1, be=-1; // index of mouse-selected vertex on click and on release (-1 if new) int mj=10; // user-controlled limit on the depth of vertex spanning tree boolean numbers = true; // toggles display of vertex numbers color soft = color(200, 200, 210); color red = color(200, 10, 10); // COLORS color blue = color(10, 10, 200); color green = color(0, 150, 0); color black = color(10, 10, 10); color magenta = color(250, 150, 200); color brown = color(100, 50, 20); void setup() { size(600, 600); // window size PFont font = loadFont("Courier-14.vlw"); textFont(font, 12); // font Courier-14.vlw must be created (see Tools>Creat Font) for (int i=0; i10) {pp=-1;}; // if closest point is too far, pp=-1 return(pp); } float d2(int j) {return (Mouse.disTo(P[j]));}; // distance from mouse to vertex P[j] void mouseReleased() { // do this when mouse released if (keyPressed) {P[bs].setFromMouse(); } // if a key is pressed, leave the dragged point here else { // otherwise, make a new edge ending at a close-by point or create a new end-point be=pick(); if (be==-1) {P[vn].setFromMouse(); be=vn; println("inserted vertex "+be); vn++;}; E[en].setFromValues(bs,be); println("inserted edge "+en+" = ("+bs+","+be+")"); en++; VST(); }; }; //************************************************************* // **** COMPUTE THE VERTEX SPANNING TREE WITH ROOT AT VERTEX 0 //************************************************************* void VST() { // computes the vertex spanning tree (sets colors of edges and points in the tree) //********************************************** // insert your code here // it should change the color of all vertices and edges in the TST //********************************************** //*********************************************************** // my placeholder code just to have something (please delete) //************************************************************ for (int i=0; ibx) {bx=P[i].x;}; if (P[i].xby) {by=P[i].y;}; if (P[i].y