package user.red;
import java.awt.*;
import java.applet.*;
class StarModel
{ //計算五角星各頂點坐標時要用到的中間結果
double temp2=Math.sin(Math.PI*2/5);
double temp3=Math.cos(Math.PI/5);
double temp4=Math.cos(Math.PI*2/5);
double temp5=Math.tan(Math.PI/5);
double temp6=Math.tan(Math.PI*2/5);
int[] calculateX(int m,int R)
{ //計算五角星各頂點的X坐標
int[] x = new int[10];
int r = (int)(R*temp4);
x[0]=m;
x[1]=m-(int)(r*temp5);
x[2]=m-(int)(R*temp2);
x[3]=m-(int)(r*temp2/temp3);
x[4]=m-(int)(2*R*temp2*temp4);
x[5]=x[0];
x[6]=m+(int)(2*R*temp2*temp4);
x[7]=m+(int)(r*temp2/temp3);
x[8]=m+(int)(R*temp2);
x[9]=m+(int)(r*temp5);
return x;
}
int[] calculateY(int n,int R)
{ //計算五角星的各頂點的Y坐標
int[] y = new int[10];
int r = (int)(R*temp4);
y[0]=n;
y[1]=n+(int)(r*temp5*temp6);
y[2]=n+R-r;
y[3]=n+R+(int)(r*temp4/temp3);
y[4]=n+(int)(2*R*temp2*temp2);
y[5]=y[0]+R+(int)(r/temp3);
y[6]=y[4];
y[7]=y[3];
y[8]=y[1];
y[9]=y[1];
return y;
}
}
public class DrawStar extends Applet
{
private static final long serialVersionUID = 1L;
int[] x=new int[10];
int[] y = new int[10];
int a=200,b=70,R=70; //大五角星的顯示坐標位置及外接圓半徑大小
//四個小五角星顯示坐標位置及外接圓半徑的大小
int a1=310,b1=45,R1=20;
int a2=350,b2=90,R2=20;
int a3=355,b3=150,R3=20;
int a4=300,b4=200,R4=20;
StarModel wu;
public void paint(Graphics g)
{
wu = new StarModel();
g.setColor(Color.red);
g.fillRect(80, 20, 700, 400);
g.setColor(Color.yellow);
g.fillPolygon(wu.calculateX(a,R),wu.calculateY(b,R),10);
g.fillPolygon(wu.calculateX(a1,R1),wu.calculateY(b1,R1),10);
g.fillPolygon(wu.calculateX(a2,R2),wu.calculateY(b2,R2),10);
g.fillPolygon(wu.calculateX(a3,R3),wu.calculateY(b3,R3),10);
g.fillPolygon(wu.calculateX(a4,R4),wu.calculateY(b4,R4),10);
}
}