arrows fixed + colors
This commit is contained in:
@@ -24,20 +24,22 @@ class Graph {
|
|||||||
|
|
||||||
void draw_points(int point_weight) {
|
void draw_points(int point_weight) {
|
||||||
strokeWeight(point_weight);
|
strokeWeight(point_weight);
|
||||||
stroke(#FF0000);
|
stroke(255);
|
||||||
for (int i = 0; i < coords.size(); i++) {
|
for (int i = 0; i < coords.size(); i++) {
|
||||||
point(coords.get(i).get(0), coords.get(i).get(1));
|
point(coords.get(i).get(0), coords.get(i).get(1));
|
||||||
text(i+1, coords.get(i).get(0)-3, coords.get(i).get(1)+5);
|
textAlign(CENTER, CENTER);
|
||||||
|
fill(0);
|
||||||
|
text(i+1, coords.get(i).get(0), coords.get(i).get(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_graph(int graph_weight, int point_weight) {
|
void draw_graph(int graph_weight, int point_weight) {
|
||||||
stroke(#550000);
|
stroke(255);
|
||||||
strokeWeight(10);
|
strokeWeight(graph_weight);
|
||||||
for (int i = 0; i < adj.size(); i++) {
|
for (int i = 0; i < adj.size(); i++) {
|
||||||
for (int idx = 0; idx < adj.get(i).size(); idx++) {
|
for (int idx = 0; idx < adj.get(i).size(); idx++) {
|
||||||
int e = adj.get(i).get(idx);
|
int e = adj.get(i).get(idx);
|
||||||
draw_arrow(coords.get(i).get(0), coords.get(i).get(1), coords.get(e).get(0), coords.get(e).get(1), point_weight, graph_weight);
|
draw_arrow(coords.get(i).get(0), coords.get(i).get(1), coords.get(e).get(0), coords.get(e).get(1), point_weight, graph_weight, 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,40 @@
|
|||||||
void draw_arrow(float x1, float y1, float x2, float y2, float offset, float weight) {
|
void draw_arrow(float x1, float y1, float x2, float y2, float offset, float weight, float distance_from_point) {
|
||||||
if (x1 == x2 && y1 == y2) return;
|
if (x1 == x2 && y1 == y2) return;
|
||||||
float angle = atan2(y2-y1, x2 - x1);
|
float angle = atan2(y2-y1, x2 - x1);
|
||||||
|
float triangle_size = dist(x1, y1, x2, y2) / 50;
|
||||||
pushMatrix();
|
pushMatrix();
|
||||||
translate(x1, y1);
|
translate(x1, y1);
|
||||||
|
PVector start = PVector.fromAngle(angle);
|
||||||
|
start.setMag(distance_from_point/2 + offset/2 + weight/2);
|
||||||
|
pushMatrix();
|
||||||
|
translate(start.x, start.y);
|
||||||
PVector v = PVector.fromAngle(angle);
|
PVector v = PVector.fromAngle(angle);
|
||||||
v.setMag(dist(x1, y1, x2, y2) - min(offset, weight) - offset/2);
|
v.setMag(dist(x1, y1, x2, y2) - 2* (offset/2 + distance_from_point/2 + weight/2) - weight/2);
|
||||||
line(0, 0, v.x, v.y);
|
line(0, 0, v.x, v.y);
|
||||||
pushMatrix();
|
pushMatrix();
|
||||||
translate(v.x, v.y);
|
translate(v.x, v.y);
|
||||||
rotate(angle);
|
rotate(angle);
|
||||||
float triangle_size = dist(x1, y1, x2, y2) / 50;
|
fill(255);
|
||||||
triangle(-triangle_size * 2, - triangle_size, 0, 0, -triangle_size * 2, triangle_size);
|
triangle(-triangle_size * 2, - triangle_size, 0, 0, -triangle_size * 2, triangle_size);
|
||||||
popMatrix();
|
popMatrix();
|
||||||
popMatrix();
|
popMatrix();
|
||||||
|
popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
int edge_weight = 20;
|
int edge_weight = 10;
|
||||||
int point_weight = 30;
|
int point_weight = 30;
|
||||||
int graph_weight = 10;
|
int graph_weight = 2;
|
||||||
if (frameCount % 60 == 0) {
|
if (frameCount % 60 == 0) {
|
||||||
|
background(0);
|
||||||
g.draw_graph(graph_weight, point_weight);
|
g.draw_graph(graph_weight, point_weight);
|
||||||
g.draw_points(point_weight);
|
g.draw_points(point_weight);
|
||||||
stroke(#00FF00);
|
stroke(#555555);
|
||||||
if (!edges.isEmpty()) {
|
if (!edges.isEmpty()) {
|
||||||
int[] edge = edges.get(0);
|
int[] edge = edges.get(0);
|
||||||
edges.remove(0);
|
edges.remove(0);
|
||||||
strokeWeight(edge_weight);
|
strokeWeight(edge_weight);
|
||||||
draw_arrow(g.coords.get(edge[0]).get(0), g.coords.get(edge[0]).get(1), g.coords.get(edge[1]).get(0), g.coords.get(edge[1]).get(1), point_weight, edge_weight);
|
draw_arrow(g.coords.get(edge[0]).get(0), g.coords.get(edge[0]).get(1), g.coords.get(edge[1]).get(0), g.coords.get(edge[1]).get(1), point_weight, edge_weight, 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ void test() {
|
|||||||
g.add_edge(0, 1);
|
g.add_edge(0, 1);
|
||||||
g.add_edge(1, 3);
|
g.add_edge(1, 3);
|
||||||
g.add_edge(1, 4);
|
g.add_edge(1, 4);
|
||||||
//g.add_edge(2, 0);
|
g.add_edge(2, 0);
|
||||||
g.add_edge(4, 5);
|
g.add_edge(4, 5);
|
||||||
g.add_edge(5, 6);
|
g.add_edge(5, 6);
|
||||||
g.add_edge(0, 2);
|
g.add_edge(0, 2);
|
||||||
g.set_coords(0, 100, 500);
|
g.set_coords(0, 500, 100);
|
||||||
g.set_coords(1, 300, 500);
|
g.set_coords(1, 200, 300);
|
||||||
g.set_coords(2, 300, 750);
|
g.set_coords(2, 780, 300);
|
||||||
g.set_coords(3, 500, 500);
|
g.set_coords(3, 100, 500);
|
||||||
g.set_coords(4, 300, 250);
|
g.set_coords(4, 300, 500);
|
||||||
g.set_coords(5, 500, 250);
|
g.set_coords(5, 300, 700);
|
||||||
g.set_coords(6, 700, 250);
|
g.set_coords(6, 300, 900);
|
||||||
vis = new boolean[]{false, false, false, false, false, false, false};
|
vis = new boolean[]{false, false, false, false, false, false, false};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user