public static void drawOval( GraphicsContext graphicsContext, final int x, final int y,…
- User
public static void drawOval( GraphicsContext graphicsContext, final int x, final int y, final int width, final int height, final Color color) { Point center = new Point(x + width / 2, y + height / 2); WritableImage writableImage = new WritableImage((int) canvas.getWidth(), (int) canvas.getHeight()); PixelWriter pixelWriter = writableImage.getPixelWriter(); int focusA = width; int focusB = height / 2; int nowX = 0; int nowY = focusB; int d = Math.round((float) (focusB * focusB) / 2 - focusA * focusB * 2 + (float) focusA / 2); while (nowY >= 0) { pixelWriter.setColor(center.getX() + nowX, center.getY() + nowY, color); pixelWriter.setColor(center.getX() + nowX, center.getY() - nowY, color); pixelWriter.setColor(center.getX() - nowX, center.getY() + nowY, color); pixelWriter.setColor(center.getX() - nowX, center.getY() - nowY, color); if (d < 0) { double error = 2 * d + 2 * focusA * nowY - focusA; nowX++; if (error <= 0) { d = d + 2 * focusB * nowX + focusB; } else { nowY--; d = d + 2 * focusB * nowX - 2 * focusA * nowY + focusB + focusA; } } else if (d > 0) { double error = 2 * d + 2 * focusB * nowX - focusB; nowY--; if (error > 0) { d = d + 2 * focusA * nowY + focusA; } else { nowX++; d = d + 2 * focusB * nowX - 2 * focusA * nowY + focusB + focusA; } } else { nowY--; nowX++; d = d + 2 * focusB * nowX - 2 * focusA * nowY + focusB + focusA; } } graphicsContext.drawImage(writableImage, 0, 0);
}мой код работает не корректно, исправь его
- Assistant