Files
mannschaftswettbewerb_info_…/bfs_visualization/draw.pde
2023-11-16 16:03:51 +01:00

34 lines
1.0 KiB
Plaintext

void draw_arrow(float x1, float y1, float x2, float y2, float offset, float weight) {
if (x1 == x2 && y1 == y2) return;
float angle = atan2(y2-y1, x2 - x1);
pushMatrix();
translate(x1, y1);
PVector v = PVector.fromAngle(angle);
v.setMag(dist(x1, y1, x2, y2) - min(offset, weight) - offset/2);
line(0, 0, v.x, v.y);
pushMatrix();
translate(v.x, v.y);
rotate(angle);
float triangle_size = dist(x1, y1, x2, y2) / 50;
triangle(-triangle_size * 2, - triangle_size, 0, 0, -triangle_size * 2, triangle_size);
popMatrix();
popMatrix();
}
void draw() {
int edge_weight = 20;
int point_weight = 30;
int graph_weight = 10;
if (frameCount % 60 == 0) {
g.draw_graph(graph_weight, point_weight);
g.draw_points(point_weight);
stroke(#00FF00);
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);
}
}
}