我正在尝试在不使用 shape 类的情况下创建方形轮廓。基本上归功于旧时尚数学。我有一个在这里创建一个圆圈:
public class CircleDemo {
public static void main(String[] args) {
Display panel = new Display(10, 2);
drawCircle(panel);
}
public static void drawCircle(Display panel) {
int centerX = panel.getWidth() / 2;
int centerY = panel.getHeight() / 2;
// Draw a circle starting at the top and going clock wise
double degAng = 270;
double radius = 150;
double x, y, radAng;
while ( true ) {
radAng = ( degAng * Math.PI ) / 180;
x = centerX + radius * Math.cos ( radAng );
y = centerY + radius * Math.sin ( radAng );
panel.drawNextPixel ( (int) x, (int) y );
degAng += 0.15;
// System.out.println ( "x = " + x + ", y = " + y );
}
}
}