import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class report10b extends Applet { int a = 4; double rad; Choice ch3; Choice ch2; Choice ch1; Choice ch4; int c = 6; int colnm = 0; Color col [] = {Color.green, Color.red, Color.yellow, Color.cyan,Color.white}; double scale = 0.8; public void init() { //intiの設定 setBackground(Color.black); //背景色は黒で Font fn = new Font("Helvetica",Font.ITALIC,24); //フォントの大きさは24イタリック /* 挿画図形の対象回転数 */ ch4 = new Choice(); // 挿画図形のサイズのチョイス ch4.addItem("6"); ch4.addItem("8"); ch4.addItem("10"); ch4.addItem("12"); ch4.addItem("14"); ch4.addItem("16"); ch4.addItem("18"); ch4.addItem("20"); add(ch4); ch4.setBounds(10,30,100,25); ch4.setFont(fn); ch4.addItemListener(new ItemAdapter()); // /* 挿画色 */ ch2 = new Choice(); // 挿画色のチョイス String colorStr [] = {"green", "red", "yellow", "cyan", "white"}; for (int i = 0; i <= 4; i++) { ch2.addItem(colorStr[i]); } add(ch2); // 挿画色表示 ch2.setBounds(150,30,100,25); ch2.setFont(fn); ch2.addItemListener(new ItemAdapter()); /* 挿画図形の対象回転数 */ ch3 = new Choice(); // 挿画図形のサイズのチョイス ch3.addItem("4"); ch3.addItem("5"); ch3.addItem("6"); ch3.addItem("7"); ch3.addItem("8"); ch3.addItem("9"); ch3.addItem("10"); add(ch3); ch3.setBounds(260,30,100,25); ch3.setFont(fn); ch3.addItemListener(new ItemAdapter()); // /* 縮小率 */ ch1 = new Choice(); ch1.addItem("0.8"); ch1.addItem("0.7"); ch1.addItem("0.6"); ch1.addItem("0.5"); add(ch1); ch1.setBounds(260,30,100,25); ch1.setFont(fn); ch1.addItemListener(new ItemAdapter()); } class ItemAdapter implements ItemListener { public void itemStateChanged(ItemEvent e) { if (e.getSource() == ch3) { String size = ch3.getSelectedItem(); a = (new Integer(size)).intValue(); repaint(); }else if (e.getSource() == ch2) { colnm = ch2.getSelectedIndex(); repaint(); }else if (e.getSource() == ch1) { String scaleStr = ch1.getSelectedItem(); scale = (new Double(scaleStr)).doubleValue(); repaint(); }else if (e.getSource() == ch4) { String count = ch4.getSelectedItem(); c = (new Integer(count)).intValue(); repaint(); } } } public void drawFra(Graphics g){ double xpos1 = 250,ypos1 = 300,r1 = 80; double xpos2,ypos2,r2; g.setColor(col[colnm]); g.drawOval((int)(xpos1 - r1), (int)(ypos1 - r1), (int)(2 * r1), (int)(2 * r1)); //真中の基準円 /* xpos1,ypos1,r1は前の円の位置 */ /* xpos2,ypos,r2は次の円の位置*/ for(int j = c;j > 0;--j){ rad = 0.0; r2 = r1 * scale; for (int rot = a;rot > 0;--rot){ // 同じ大きさの円を対象回転数だけ挿画 xpos2 = (r1 + r2) * Math.cos(rad) + xpos1; ypos2 = (r1 + r2) * Math.sin(rad) + ypos1; g.setColor(col[colnm]); g.drawOval((int)(xpos2 - r2), (int)(ypos2 - r2), (int)(2 * r2), (int)(r2 * 2)); rad = rad + (2 * Math.PI / a); } r1 = r1 * scale; } } public void paint(Graphics g) { drawFra(g); } }