import javax.swing.*; import java.applet.Applet; import java.awt.*; import java.awt.geom.Point2D; import java.util.Vector; public class DrawStar extends Applet { Vector<Point2D.Double> points = new Vector<Point2D.Double>(); Polygon poa,pob; double r = 100; double n = r+50; public DrawStar(){ computerPoints(5); } public void init(){ computerPoints(5); } private void computerPoints(int n){ double pi = 3.14159265; points.add(new Point2D.Double(0,r)); for(int i=1;i<n;i++) { double x = r*Math.sin(2*pi*i/n); double y = r*Math.cos(2*pi*i/n); points.add(new Point2D.Double(x,y)); } } public void paint(Graphics g) { fillPolygonA(); fillPolygonB(); g.drawPolygon(poa); g.drawPolygon(pob); } private void fillPolygonA() { poa = new Polygon(); for(int i=0;i<points.size();i++) { int x = (int)(points.get(i).getX()+n); int y = (int)(points.get(i).getY()+n); poa.addPoint(x, y); } } private void fillPolygonB() { int s = points.size(); pob = new Polygon(); int i=0; for(;;) { int x = (int)(points.get(i).getX()+n); int y = (int)(points.get(i).getY()+n+200); pob.addPoint(x, y); i+=2; if(i%s==0) break; else i%=s; } } public static void main(String[] args ) { JFrame f = new JFrame("Test"); f.setSize(300,600); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.add(new DrawStar()); f.setVisible(true); } }