41 lines
1.3 KiB
Plaintext
41 lines
1.3 KiB
Plaintext
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;
|
|
float angle = atan2(y2-y1, x2 - x1);
|
|
float triangle_size = dist(x1, y1, x2, y2) / 50;
|
|
pushMatrix();
|
|
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);
|
|
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);
|
|
pushMatrix();
|
|
translate(v.x, v.y);
|
|
rotate(angle);
|
|
fill(255);
|
|
triangle(-triangle_size * 2, - triangle_size, 0, 0, -triangle_size * 2, triangle_size);
|
|
popMatrix();
|
|
popMatrix();
|
|
popMatrix();
|
|
}
|
|
|
|
void draw() {
|
|
int edge_weight = 10;
|
|
int point_weight = 30;
|
|
int graph_weight = 2;
|
|
if (frameCount % 60 == 0) {
|
|
background(0);
|
|
g.draw_graph(graph_weight, point_weight);
|
|
g.draw_points(point_weight);
|
|
stroke(#555555);
|
|
if (!edges.isEmpty()) {
|
|
int[] edge = edges.get(0);
|
|
edges.remove(0);
|
|
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, 15);
|
|
}
|
|
}
|
|
}
|