import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; import java.lang.Math; public class Cycloid extends Applet { static final int a = 80; static final Color colorTable[] = {Color.red,Color.blue,Color.green}; public void paint (Graphics grph){ int c = 0; for (int b = a/2; b <= a+a/2; b += a/2){ int g = 0; grph.setColor (colorTable[c]); int stx,sty; stx = sty = 0; for(double th = -Math.PI; th <= 3.0*Math.PI; th += Math.PI / 45.0){ double x = (double)a * th - b * Math.sin(th); double y = (double)a - b * Math.cos(th); int gx = (int)(60.0 + x); int gy = (int)(120.0 - 0.4 * y); if (gx < 0.0 || gx > 639){ g=0; continue; } if (g!=1){ stx = gx; sty = gy; g=1; } grph.drawLine (stx, sty, gx, gy); stx = gx; sty = gy; } c++; } } }