Skip to content

Commit

Permalink
Add FUNCTIONS TO AUTOMATICALLY GENERATE 3-CONNECTED GRAPH
Browse files Browse the repository at this point in the history
  • Loading branch information
xiz13010 committed Nov 19, 2014
1 parent c50eb6c commit 4343b60
Showing 1 changed file with 42 additions and 22 deletions.
64 changes: 42 additions & 22 deletions drawing/drawing.pde
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

final int DRAW_NORMAL=1;
final int DRAW_DRAG=2;
final int Vertex_Rad=8;
// define parameters for rectangular button
int rectX=500, rectY=500;
int rectX1=500, rectY1=500;
int rectX2=500, rectY2=550;
int rectwidth=80;
int rectheight=40;
color rectColor;
Expand All @@ -16,8 +18,8 @@ void setup() {
background(255);
rectColor=(150);
rectHighlight=color(255,0,0);
rectX=500;
rectY=500;
rectX1=500;
rectY1=500;
noStroke();
}
Graph G=new Graph();
Expand Down Expand Up @@ -70,9 +72,10 @@ void mouseDragged(){

}
void mousePressed(){
if(vertex_under_mouse==null && !check_mouse_over_button(rectX,rectY,rectheight,rectwidth)){
if(vertex_under_mouse==null && !check_mouse_over_button(rectX1,rectY1,rectheight,rectwidth) &&!check_mouse_over_button(rectX2,rectY2,rectheight,rectwidth)){
G.V.add(new Vertex(mouseX, mouseY,true));
}

}

void mouseReleased(){
Expand All @@ -92,46 +95,63 @@ void mouseReleased(){

void mouse_over_BUTTON(){

if(check_mouse_over_button(rectX,rectY,rectheight,rectwidth)){
if(check_mouse_over_button(rectX1,rectY1,rectheight,rectwidth)){
fill(255,0,0);
}else {
fill(rectColor);
}
noStroke();
rect(rectX,rectY,rectwidth,rectheight);
rect(rectX1,rectY1,rectwidth,rectheight);
textSize(10);
fill(0, 0, 0);
text("Initial Graph",rectX1+rectwidth/8,rectY1+rectheight/2);

if(check_mouse_over_button(rectX2,rectY2,rectheight,rectwidth))
fill(255,0,0);
else
fill(rectColor);

rect(rectX2,rectY2,rectwidth,rectheight);
textSize(10);
fill(0, 0, 0);
text("Initial Graph",rectX+rectwidth/8,rectY+rectheight/2);

text("Reset",rectX2+rectwidth/8,rectY2+rectheight/2);
}



void mouseClicked(){
if(check_mouse_over_button(rectX,rectY,rectheight,rectwidth))
//draw edges should be implemented by pressing button.
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++){
ArrayList index=new ArrayList ();
for(int r=0;r<G.V.size();r++){
index.add(r);
}
}
index.remove(i);
for(int j=0; j<3;j++){
stroke(0,0,255);
strokeWeight(2);
int k=int(random(index.size()));
int l=(Integer)index.get(k);
line(G.V.get(i).x,G.V.get(i).y,G.V.get(l).x,G.V.get(l).y);
//add the drawn edge
G.E.add(new Edge(G.V.get(i),G.V.get(l)));
index.remove(k);
for(int j=0;j<=3;j++){
stroke(0,0,255);
strokeWeight(2);
int k=int(random(index.size()));
int l=(Integer)index.get(k);
println(l);
//add the drawn edge to the graph and the Vertex arraylist
//if(G.ValidNewEdge(G.V.get(i),G.V.get(l))){
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 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);
}
}
if(check_mouse_over_button(rectX2,rectY2,rectheight,rectwidth))

G.E.clear();
}


0 comments on commit 4343b60

Please sign in to comment.