Skip to content

Commit

Permalink
updated version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
xiz13010 committed Nov 19, 2014
1 parent 4343b60 commit 66e264b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
6 changes: 6 additions & 0 deletions drawing/Graph.pde
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ class Graph{
}
return true;
}

boolean check3edges_per_vertex(Vertex v){
if(v.E.size()<3) return true;
if(v.E.size()>=3) return false;
return true;
}
}
31 changes: 9 additions & 22 deletions drawing/drawing.pde
Original file line number Diff line number Diff line change
Expand Up @@ -117,41 +117,28 @@ void mouse_over_BUTTON(){
text("Reset",rectX2+rectwidth/8,rectY2+rectheight/2);
}



void mouseClicked(){
if(check_mouse_over_button(rectX1,rectY1,rectheight,rectwidth)){
//draw edges should be implemented by pressing button.
if (G.V.size()<=3) throw new RuntimeException("Requires at least 5 points");
ArrayList index=new ArrayList ();
for(int i=0;i<G.V.size();i++){
for(int r=0;r<G.V.size();r++){
index.add(r);
}
index.remove(i);
for(int j=0;j<=3;j++){
do{
stroke(0,0,255);
strokeWeight(2);
int k=int(random(index.size()));
int l=(Integer)index.get(k);
int l= int(random(G.V.size()));
println(l);
//add the drawn edge to the graph and the Vertex arraylist
//if(G.ValidNewEdge(G.V.get(i),G.V.get(l))){
//add the drawn edge to the graph
if(G.ValidNewEdge(G.V.get(i),G.V.get(l))){ //have to check the whether the randomly selected vertex has three edges????
G.E.add(new Edge(G.V.get(i),G.V.get(l)));
line(G.V.get(i).x,G.V.get(i).y,G.V.get(l).x,G.V.get(l).y);
index.remove(k);
}
}
//remove the repeatedly added edges from the edge list
for(int i=0;i<G.E.size();++i){
for(int j=0;j<G.E.size();++j)
if(G.E.get(i).v2==G.E.get(j).v1 && G.E.get(i).v1==G.E.get(j).v2)
G.E.remove(j);
}
}while(G.check3edges_per_vertex(G.V.get(i)));
}
}
if(check_mouse_over_button(rectX2,rectY2,rectheight,rectwidth))

if(check_mouse_over_button(rectX2,rectY2,rectheight,rectwidth)){
G.E.clear();
G.V.clear();
}
}


0 comments on commit 66e264b

Please sign in to comment.