arrows fixed + colors

This commit is contained in:
DarianTr
2023-11-17 19:50:30 +01:00
parent d5d9994f18
commit a32425724c
3 changed files with 29 additions and 20 deletions

View File

@@ -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;
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) - 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);
pushMatrix();
translate(v.x, v.y);
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);
popMatrix();
popMatrix();
popMatrix();
}
void draw() {
int edge_weight = 20;
int edge_weight = 10;
int point_weight = 30;
int graph_weight = 10;
int graph_weight = 2;
if (frameCount % 60 == 0) {
background(0);
g.draw_graph(graph_weight, point_weight);
g.draw_points(point_weight);
stroke(#00FF00);
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);
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);
}
}
}