Skip to content

Commit

Permalink
Add functions to automatically generate the initial 3-connected graph
Browse files Browse the repository at this point in the history
  • Loading branch information
xiz13010 committed Nov 18, 2014
1 parent b5bae42 commit c50eb6c
Showing 1 changed file with 74 additions and 2 deletions.
76 changes: 74 additions & 2 deletions drawing/drawing.pde
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
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 rectwidth=80;
int rectheight=40;
color rectColor;
color rectHighlight;
boolean rectover=false;

Vertex drag_start;
Vertex vertex_under_mouse;
void setup() {
size(640, 360);
size(600, 600);
background(255);
rectColor=(150);
rectHighlight=color(255,0,0);
rectX=500;
rectY=500;
noStroke();
}
Graph G=new Graph();
Expand All @@ -17,6 +30,9 @@ void draw() {
for(Vertex i:G.V){
i.draw();
}

mouse_over_BUTTON();

//Draw Edges
strokeWeight(2);
for(Edge i:G.E){
Expand All @@ -30,6 +46,15 @@ void draw() {
//Draw the dragged line;
}
}

boolean check_mouse_over_button(int x, int y,int _height,int _width){
if(mouseY>=y && (mouseY-y<_height) &&(mouseX-x<_width)&& mouseX>=x)
rectover=true;
else rectover=false;

return rectover;

}
void mouseMoved(){
vertex_under_mouse=null;
for(Vertex i:G.V){
Expand All @@ -45,7 +70,7 @@ void mouseDragged(){

}
void mousePressed(){
if(vertex_under_mouse==null){
if(vertex_under_mouse==null && !check_mouse_over_button(rectX,rectY,rectheight,rectwidth)){
G.V.add(new Vertex(mouseX, mouseY,true));
}
}
Expand All @@ -63,3 +88,50 @@ void mouseReleased(){
}
}
}


void mouse_over_BUTTON(){

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

}



void mouseClicked(){
if(check_mouse_over_button(rectX,rectY,rectheight,rectwidth))
//draw edges should be implemented by pressing button.
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);
}
}
//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);
}

}

0 comments on commit c50eb6c

Please sign in to comment.