//----------------------------------------------------------- // // RotaryEngine for JAVA // Copy right(c)1996 Tatsuhiko.Sakamoto All right reserved // E-mail PGB02215@niftyserve.or.jp //----------------------------------------------------------- import java.applet.Applet; import java.awt.*; public class RotaryEngine extends Applet implements Runnable { int i; int last = 10; int cx = 70; int cy = 100; int smallR = 10; int largeR = 75; int roterR = 130; int internalGearR; int stationaryGearR; Polygon RotaryHousingShape = new Polygon(); Thread thread; public void init(){ stationaryGearR = smallR * 2; internalGearR = stationaryGearR + smallR; for(int i = 0;i<37;i++) { int Angle = 360*i/36; int x = (int)(Math.cos((Angle*3+180)*Math.PI/180)*smallR + Math.cos(Angle*Math.PI / 180)*largeR); int y = (int)(Math.sin((Angle*3+180)*Math.PI/180)*smallR + Math.sin(Angle*Math.PI / 180)*largeR); RotaryHousingShape.addPoint(cx+x,cy-y); } } public void start(){ if(thread == null) { thread = new Thread(this); thread.start(); } } public void stop(){ if (thread != null){ thread.stop(); thread = null; } } public void paint(Graphics g){ int Angle = 120*i/last; int x = (int)(cx + Math.cos((Angle*3+180)*Math.PI/180)*smallR); int y = (int)(cy + Math.sin((Angle*3+180)*Math.PI/180)*smallR); int x1 = (int)(Math.cos(Angle*Math.PI / 180)*largeR); int y1 = -(int)(Math.sin(Angle*Math.PI / 180)*largeR); int x2 = (int)(Math.cos((Angle+120)*Math.PI / 180)*largeR); int y2 = -(int)(Math.sin((Angle+120)*Math.PI / 180)*largeR); int x3 = (int)(Math.cos((Angle+240)*Math.PI / 180)*largeR); int y3 = -(int)(Math.sin((Angle+240)*Math.PI / 180)*largeR); g.drawPolygon(RotaryHousingShape); g.drawArc(x+x1-roterR,y-y1-roterR,roterR*2,roterR*2,-Angle + 150,60); g.drawArc(x+x2-roterR,y-y2-roterR,roterR*2,roterR*2,-Angle + 30,60); g.drawArc(x+x3-roterR,y-y3-roterR,roterR*2,roterR*2,-Angle + 270,60); g.drawOval(x-internalGearR,y-internalGearR, internalGearR*2,internalGearR*2); g.drawOval(cx-stationaryGearR,cy-stationaryGearR, stationaryGearR*2,stationaryGearR*2); } public void run(){ while(true) { try { Thread.sleep(80); }catch (InterruptedException e){ break; } i++; if(i >= last){ i = 0; } repaint(); } } }