-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrafoGrafico.java
More file actions
95 lines (77 loc) · 2.33 KB
/
GrafoGrafico.java
File metadata and controls
95 lines (77 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Universidad Del Valle
* Pablo Díaz 13203
* Adolfo Morales 13014
* Jorge García
*/
package astar;
import java.awt.Color;
import java.awt.Graphics;
import java.util.List;
import java.util.Set;
import javax.swing.JPanel;
/**
*
* @author Pablo
*/
public class GrafoGrafico extends JPanel{
private final Grafo grafo;
private final int EscalaX;
private final int EscalaY;
private final int ancho;
private final int alto;
private final List<Nodo> path;
private final Set<Nodo> nodosEvaluados;
public GrafoGrafico(Grafo grafo, int ancho, int alto, List<Nodo> path, Set<Nodo> nodosEvaluados) {
this.grafo = grafo;
this.ancho = ancho;
this.alto = alto;
this.path = path;
this.EscalaX=400/ancho;
this.EscalaY=400/alto;
this.nodosEvaluados=nodosEvaluados;
setSize(EscalaX * ancho, EscalaY * alto);
setVisible(true);
}
private void fillRect(Graphics graphics, int x, int y) {
graphics.fill3DRect(EscalaX*x, EscalaY*y, EscalaX, EscalaY, true);
}
public void paintObstacles(Graphics graphics) {
graphics.setColor(Color.BLACK);
for (int x = 0; x < alto; ++x) {
for (int y = 0; y < ancho; ++y) {
if (grafo.getNodo(x, y).isObstaculo()) {
fillRect(graphics, x, y);
}
}
}
}
public void paintGrafo(Graphics graphics){
graphics.setColor(Color.gray);
for (int y = 0; y < alto; y++)
{
for (int x = 0; x < ancho; x++)
{
fillRect(graphics,x,y);
}
}
}
@Override
public void paint(Graphics graphics) {
graphics.setColor(Color.DARK_GRAY);
paintGrafo(graphics);
paintObstacles(graphics);
paintPath(graphics);
//paintEvaluatedNodes(graphics);
}
private void paintPath(Graphics graphics) {
graphics.setColor(Color.red);
for (Nodo n1: nodosEvaluados)
fillRect(graphics,n1.getX(),n1.getY());
graphics.setColor(Color.GREEN);
for (Nodo n : path) {
int x = n.getX(); int y = n.getY();
fillRect(graphics, x, y);
}
}
}