I have the following code to print a flag in Java Applet, the last statement prints the coordinates of a polygon, when I run the code it prints the coordinates 14 times, which is not logical, the loop should iterate only 7 times
import java.applet.*;
import java.awt.*;
public class New1 extends Applet
{
public void paint(Graphics g)
{
super.setSize(600,600);
int centerX=110;
int centerY=225;
int outerCircleDiameter = 120;
int innerCircleDiameter = 70;
int outerCircleRadius = outerCircleDiameter / 2;
int innerCircleRadius = innerCircleDiameter / 2;
int[] xPoints = new int[14];
int[] yPoints = new int[14];
double angle = Math.PI / 2;
double angleIncrement = 2 * Math.PI / 7;
for (int i = 0; i < 14; i++)
{
int radius = i % 2 == 0 ? outerCircleRadius : innerCircleRadius;
int x = (int) (centerX + Math.cos(angle) * radius);
int y = (int) (centerY - Math.sin(angle) * radius);
xPoints[i] = x;
yPoints[i] = y;
angle += angleIncrement;
}
angleIncrement = 2 * Math.PI / 7;
angle = Math.PI / 2;
g.setColor(Color.white);
g.fillPolygon(xPoints, yPoints, 14);
int[] xiPoints = new int[7];
int[] yiPoints = new int[7];
g.setColor(Color.white);
for (int i = 0; i < 7; i++)
{
int x = (int) (centerX + Math.cos(angle) * innerCircleRadius);
int y = (int) (centerY - Math.sin(angle) * innerCircleRadius);
xiPoints[i] = x;
yiPoints[i] = y;
angle += angleIncrement;
}
for(int i=0;i<7;i++)
{
System.out.println("("+xiPoints[i]+","+yiPoints[i]+")");
}
g.setColor(Color.green);
g.fillPolygon(xiPoints, yiPoints, 7);
g.setColor(Color.blue);
g.drawOval(centerX - innerCircleRadius, centerY - innerCircleRadius, innerCircleDiameter, innerCircleDiameter);
}
}
when i run the applet i get the following output from the print statement:
(110,190)
(82,203)
(75,232)
(94,256)
(125,256)
(144,232)
(137,203)
(110,190)
(82,203)
(75,232)
(94,256)
(125,256)
(144,232)
(137,203)
does anyone know the reason for that ?