import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image;
import java.awt.Dimension;

/* <applet code="houbutsu.class" width="800" height="500"></applet> */

public class houbutsu extends Applet implements Runnable {
  final static double grav = 9.81;        // 重力加速度
  final static double x_start = 20.0;     // スタート位置 x
  final static double y_start = 220.0;     // スタート位置 y
  final static double vx_start = 50.0;    // 初速 x
  final static double vy_start = 30.0;    // 初速 y
  final static double delta = 0.12;        // 時間間隔(調整可能）
  final static int hosei = 30;
  final static int speed = 100;            // 画面表示のスピード（調整可能）

  double x, y, prev1_x, prev1_y, prev2_x, prev2_y, stop_y;
  double t;
  double dim_y;

  Thread th;
  Image buff;
  Graphics ct;
  Dimension dim;

  public void init() {
    t = 0.0;
    
    th = new Thread(this);
    th.start();
    dim = getSize();
    buff = createImage(dim.width, dim.height);
    dim_y = (double)dim.height;
  }    

  public void run() {
    try {
      while (true) {

/* 描画関係 */
        prev2_x = prev1_x;
        prev2_y = prev1_y;
        prev1_x = x;
        prev1_y = y;

/* 以下、運動の記述 */
        x = x_start + t * vx_start;
        y = dim_y - (stop_y = y_start + t * vy_start - 0.5 * grav * t * t) - hosei;
        t += delta;

/* 停止条件 */
        if (stop_y < 0)
          break;

        repaint();
        Thread.sleep(speed);
      }
    } catch (InterruptedException e) { };
  }


  public void update(Graphics g) {
    paint(g);
  }

  public void paint(Graphics g) {
    if (ct == null) ct = buff.getGraphics();
    ct.setColor(Color.white);
    ct.fillRect((int)prev2_x, (int)prev2_y, 20, 20);
    ct.fillRect((int)prev1_x, (int)prev1_y, 20, 20);
//    ct.fillRect(0, 0, dim.width, dim.height);
    ct.setColor(Color.red);
    ct.fillOval((int)x, (int)y, 20, 20);
    g.drawImage(buff, 0, 0, this);
  }
}
/* end */
