/  *  *

* 中点画圆算法(八分之一圆)的简单实现,从控制台输入两对坐标,applet程序实现描点画线。

* @author LOOK

*  

import java.applet.Applet;

import java.awt.Color;

import java.awt.Graphics;

import java.util.Scanner;


public class MidPointCircle extends Applet {

int a;


public void init() {

setSize(300, 300);

Scanner sc = new Scanner(System.in);

System.out.println("请输入圆的半径");

a = sc.nextInt();

}


public void paint(Graphics g) {

g.setColor(Color.pink);

for (int i = 10; i <= 210; i += 10) {

g.drawLine(i, 10, i, 210);// 竖线

g.drawLine(10, i, 210, i);// 横线

}

g.setColor(Color.BLACK);

g.drawLine(10, 210, 220, 210);// x坐标

g.drawLine(10, 0, 10, 210);// y坐标

int r = a;

int x, y;

double d;

x = 0;

y = r;

d = 1.25 - r;

g.drawOval(x * 10 - 2 + 10, 210 - y * 10 - 2, 4, 4);// 描点

while (x <= y) {

if (d < 0) {

d += 2 * x + 3;

} else {

d += 2 * (x - y) + 5;

y--;

}

x++;

g.drawOval(x * 10 - 2 + 10, 210 - y * 10 - 2, 4, 4);// 描点

}

}

}