public void paint(Graphics g) {
super.paint(g);
for(int t=1;t<=this.Lados-1;t++)
{
int dx=0,dy=0;
int x1 = vertices[t].getX();
int x0 = vertices[t-1].getX();
int y1 = vertices[t].getY();
int y0 = vertices[t-1].getY();
dx = x1 - x0;
dy = y1 - y0;
if (Math.abs(dx) > Math.abs(dy))
{
float m = (float) dy / (float) dx;
float b = y0 - m * x0;
if(dx<0)
dx = -1;
else
dx = 1;
while (x0 != x1)
{
x0 += dx;
y0 = Math.round(m*x0 + b);
g.drawLine( x0, y0, x0, y0);
}
} else
if (dy != 0)
{
float m = (float) dx / (float) dy;
float b = x0 - m*y0;
if(dy<0)
dy = -1;
else
dy = 1;
while (y0 != y1)
{
y0 += dy;
x0 = Math.round(m * y0 + b);
g.drawLine( x0, y0, x0, y0);
}
}
}//fin for
if (this.Lados>0)
g.drawLine( vertices[this.Lados -1].getX(), vertices[this.Lados -1].getY(), vertices[0].getX(), vertices[0].getY());
}
public void DibujarPoligono()
{
Poligonos();
repaint();
}
0 comentarios:
Publicar un comentario