import java.awt.*; import java.applet.*; import java.lang.*; public class kido extends Applet implements Runnable{ int center_x = 210; /* ‘¾—z‚ÌxÀ•W */ int center_y = 240; /* ‘¾—z‚ÌyÀ•W */ int x1,y1; /* ’n‹…‚ÌÀ•W */ int x2,y2; /* ‰Î¯‚ÌÀ•W */ int earth_r = 100; /* ’n‹…‚Ì‹O“¹”¼Œa */ int mars_r = 152; /*‰Î¯‚Ì‹O“¹”¼Œa */ double earth_w= 10*2*Math.PI/365; /* ’n‹…‚ÌŠp‘¬“x */ double mars_w= 10*2*Math.PI/687; /* ‰Î¯‚ÌŠp‘¬“x */ double t; /* ŽžŠÔ */ Thread thre=null; Image offs; Graphics grf; Button Restart = new Button("Restart"); Button Start = new Button("Continue"); Button Stop = new Button("Stop"); int value = 0; public void init(){ /* ‰ŠúÝ’è */ resize(420,470); offs = createImage( 420,470 ); grf = offs.getGraphics(); setLayout(new BorderLayout()); Panel p = new Panel(); p.setLayout(new GridLayout(1,4,3,0)); p.add(Restart); p.add(Start); p.add(Stop); add("North",p); Restart.disable(); Start.disable(); } public void start() { /* ƒXƒŒƒbƒhAƒXƒ^[ƒg */ if(thre == null){ thre= new Thread(this); thre.start(); } } public void stop() { /* ƒXƒŒƒbƒhAƒXƒgƒbƒv */ if(thre != null){ thre.stop(); thre=null; } } public boolean action(Event evt, Object arg) { if ("Continue".equals(arg)){ thre.resume(); Restart.disable(); Stop.enable(); Start.disable(); } else if ("Stop".equals(arg)){ thre.suspend(); Restart.enable(); Start.enable(); Stop.disable(); } else if ("Restart".equals(arg)){ thre = new Thread(this); thre.start(); Restart.disable(); Start.disable(); Stop.enable(); } return true; } public void run() { /* ŒvŽZAƒAƒjƒ[ƒVƒ‡ƒ“‚Ì’†S•” */ while(thre!=null){ for(t=0; t<10000; t=t+0.5) { x1 = center_x+(int)(earth_r*Math.sin(t*earth_w)); y1 = center_y+(int)(earth_r*Math.cos(t*earth_w)); x2 = center_x+(int)(mars_r*Math.sin(t*mars_w)); y2 = center_y+(int)(mars_r*Math.cos(t*mars_w)); repaint(); try{ Thread.sleep(100);} catch (InterruptedException e) { } } } } public void paint(Graphics g){ /* GIF‚Ì•`‰æ */ grf.setColor(Color.black); grf.fillRect(0,0,420,470); grf.setColor(Color.yellow); grf.drawLine(center_x,center_y,center_x,470); grf.setColor(Color.white); grf.drawLine(center_x,center_y,x1,y1); grf.setColor(Color.yellow); grf.drawLine(center_x,center_y,x2,y2); grf.setColor(Color.white); grf.drawLine(x1,y1,x2,y2); grf.setColor(Color.yellow); grf.fillOval(center_x-10,center_y-10,20,20); /* ‘¾—z */ grf.setColor(Color.white); grf.drawOval(center_x-mars_r,center_y-mars_r,2*mars_r,2*mars_r); /*‰Î¯‹O“¹ */ grf.setColor(Color.cyan); grf.fillOval(center_x-4,center_y+100-4,8,8); /* ’n‹… */ grf.fillOval(x1-4,y1-4,8,8); /* ’n‹… */ grf.setColor(new Color(255,120,0)); grf.fillOval(x2-6,y2-6,12,12); /* ‰Î¯ */ grf.fillOval(center_x-6,392-6,12,12); /* ‰Î¯ */ if (t >= 68.7){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*earth_w))-4,8,8); grf.setColor(Color.white); grf.drawLine(center_x,center_y,center_x+(int)(earth_r*Math.sin(68.7*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*earth_w))); grf.drawLine(center_x,392,center_x+(int)(earth_r*Math.sin(68.7*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*earth_w))); } if (t >= 68.7*2){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*2*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*2*earth_w))-4,8,8); grf.setColor(Color.white); grf.drawLine(center_x,center_y,center_x+(int)(earth_r*Math.sin(68.7*2*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*2*earth_w))); grf.drawLine(center_x,392,center_x+(int)(earth_r*Math.sin(68.7*2*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*2*earth_w))); } if (t >= 68.7*3){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*3*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*3*earth_w))-4,8,8); grf.setColor(Color.white); grf.drawLine(center_x,center_y,center_x+(int)(earth_r*Math.sin(68.7*3*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*3*earth_w))); grf.drawLine(center_x,392,center_x+(int)(earth_r*Math.sin(68.7*3*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*3*earth_w))); } if (t >= 68.7*4){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*4*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*4*earth_w))-4,8,8); grf.setColor(Color.white); grf.drawLine(center_x,center_y,center_x+(int)(earth_r*Math.sin(68.7*4*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*4*earth_w))); grf.drawLine(center_x,392,center_x+(int)(earth_r*Math.sin(68.7*4*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*4*earth_w))); } if (t >= 68.7*5){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*5*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*5*earth_w))-4,8,8); } if (t >= 68.7*6){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*6*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*6*earth_w))-4,8,8); } if (t >= 68.7*7){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*7*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*7*earth_w))-4,8,8); } if (t >= 68.7*8){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*8*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*8*earth_w))-4,8,8); } if (t >= 68.7*9){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*9*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*9*earth_w))-4,8,8); } if (t >= 68.7*10){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*10*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*10*earth_w))-4,8,8); } if (t >= 68.7*11){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*11*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*11*earth_w))-4,8,8); } if (t >= 68.7*12){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*12*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*12*earth_w))-4,8,8); } if (t >= 68.7*13){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*13*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*13*earth_w))-4,8,8); } if (t >= 68.7*14){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*14*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*14*earth_w))-4,8,8); } if (t >= 68.7*15){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*15*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*15*earth_w))-4,8,8); } if (t >= 68.7*16){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*16*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*16*earth_w))-4,8,8); } g.drawImage(offs,0,0,this); } public void update(Graphics g){ if (t >= 68.7){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*earth_w))-4,8,8); grf.setColor(Color.white); grf.drawLine(center_x,center_y,center_x+(int)(earth_r*Math.sin(68.7*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*earth_w))); grf.drawLine(center_x,392,center_x+(int)(earth_r*Math.sin(68.7*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*earth_w))); } if (t >= 68.7*2){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*2*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*2*earth_w))-4,8,8); grf.setColor(Color.white); grf.drawLine(center_x,center_y,center_x+(int)(earth_r*Math.sin(68.7*2*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*2*earth_w))); grf.drawLine(center_x,392,center_x+(int)(earth_r*Math.sin(68.7*2*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*2*earth_w))); } if (t >= 68.7*3){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*3*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*3*earth_w))-4,8,8); grf.setColor(Color.white); grf.drawLine(center_x,center_y,center_x+(int)(earth_r*Math.sin(68.7*3*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*3*earth_w))); grf.drawLine(center_x,392,center_x+(int)(earth_r*Math.sin(68.7*3*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*3*earth_w))); } if (t >= 68.7*4){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*4*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*4*earth_w))-4,8,8); grf.setColor(Color.white); grf.drawLine(center_x,center_y,center_x+(int)(earth_r*Math.sin(68.7*4*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*4*earth_w))); grf.drawLine(center_x,392,center_x+(int)(earth_r*Math.sin(68.7*4*earth_w)),center_y+(int)(earth_r*Math.cos(68.7*4*earth_w))); } if (t >= 68.7*5){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*5*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*5*earth_w))-4,8,8); } if (t >= 68.7*6){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*6*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*6*earth_w))-4,8,8); } if (t >= 68.7*7){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*7*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*7*earth_w))-4,8,8); } if (t >= 68.7*8){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*8*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*8*earth_w))-4,8,8); } if (t >= 68.7*9){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*9*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*9*earth_w))-4,8,8); } if (t >= 68.7*10){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*10*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*10*earth_w))-4,8,8); } if (t >= 68.7*11){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*11*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*11*earth_w))-4,8,8); } if (t >= 68.7*12){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*12*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*12*earth_w))-4,8,8); } if (t >= 68.7*13){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*13*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*13*earth_w))-4,8,8); } if (t >= 68.7*14){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*14*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*14*earth_w))-4,8,8); } if (t >= 68.7*15){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*15*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*15*earth_w))-4,8,8); } if (t >= 68.7*16){ grf.setColor(Color.cyan); grf.fillOval(center_x+(int)(earth_r*Math.sin(68.7*16*earth_w))-4,center_y+(int)(earth_r*Math.cos(68.7*16*earth_w))-4,8,8); } g.drawImage(offs,0,0,this); paint(g); } }