回覆列表
  • 1 # 灝天居士

    import javax.swing.JFrame;

    public class EdgeFill {

    public static void main(String args[]) {

    // A(3,3)B(6,20)C(15,18)D(20,3)

    // AB BD AC CD

    new EdgeFill();

    }

    private TwoDimen env;

    public EdgeFill() {

    JFrame frame = new JFrame();

    env = new TwoDimen();

    frame.getContentPane().add(env);

    frame.setBounds(100, 100, 600, 600);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setResizable(false);

    frame.setVisible(true);

    int[] x = new int[] { 3, 6, 20, 15 };

    int[] y = new int[] { 3, 20, 3, 18 };

    for (int i = 0; i < x.length; i++) {

    if (i < x.length - 1)

    edgeFillOnce(x[i], y[i], x[i + 1], y[i + 1]);

    else

    edgeFillOnce(x[i], y[i], x[0], y[0]);

    }

    }

    private void edgeFillOnce(int x1, int y1, int x2, int y2) {

    int k, i, j;

    float x, y, dx, dy;

    k = Math.abs(x2 - x1);

    if (Math.abs(y2 - y1) > k) {

    k = Math.abs(y2 - y1);

    }

    dx = (float) (x2 - x1) / k;

    dy = (float) (y2 - y1) / k;

    x = (float) x1;

    y = (float) y1;

    for (i = 0; i < k+1; i++) {

    // env.drawPoint((int)(x+0.5), (int)(y+0.5));

    for (j = (int)

  • 中秋節和大豐收的關聯?
  • 一些好聽的甜品名字?