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)

java如何实现填充算法

相关新闻

联系我们

联系我们

888-888-8888

在线咨询: 点击这里给我发消息

邮件:admin@sytnsw.cn

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部