サインカーブのグラフを表示する



// (FAI SysOp 村上さんのソースです)

import java.awt.*;
import java.applet.*;

public class test002 extends java.applet.Applet {
        public void paint(Graphics g) {
                Dimension d = size();
                int cx = 0;
                int cy = (d.height / 2);
                double radian = 2 * Math.PI;
                g.setColor(Color.red);
                g.drawLine(cx, cy, d.width, cy);
                g.setColor(Color.blue);
                for(int x = 0; x <= d.width; ++x)  {
                        double sine = Math.sin((double)x / d.width * radian * 3);
                        int y = (int)((1.0 - sine) * (d.height / 2));
                        g.drawLine(cx, cy, x, y);
                        cx = x;
                        cy = y;
                }
        }
}