refactor: 修改绘制辅助函数以支持浮点半径,更新精灵结构体以使用浮点数表示半径,确保图形处理更精确。
This commit is contained in:
@@ -103,27 +103,27 @@ func DrawLineOnImage(img *image.RGBA, x0, y0, x1, y1 int, color color.Color) {
|
||||
}
|
||||
|
||||
// 辅助函数:在图像上绘制圆
|
||||
func DrawCircleOnImage(img *image.RGBA, x0, y0, radius int, color color.Color) {
|
||||
func DrawCircleOnImage(img *image.RGBA, x0, y0 int, radius float64, color color.Color) {
|
||||
r, g, b, a := color.RGBA()
|
||||
r8, g8, b8, a8 := uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8)
|
||||
|
||||
// 使用Bresenham算法绘制圆
|
||||
x := 0
|
||||
y := radius
|
||||
x := float64(0)
|
||||
y := float64(radius)
|
||||
d := 3 - 2*radius
|
||||
|
||||
bounds := img.Bounds()
|
||||
|
||||
for {
|
||||
// 绘制8个对称点,但只在图像范围内
|
||||
DrawPointIfInBounds(img, bounds, x0+x, y0+y, r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0+x, y0-y, r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0-x, y0+y, r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0-x, y0-y, r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0+y, y0+x, r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0+y, y0-x, r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0-y, y0+x, r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0-y, y0-x, r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0+int(x), y0+int(y), r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0+int(x), y0-int(y), r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0-int(x), y0+int(y), r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0-int(x), y0-int(y), r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0+int(y), y0+int(x), r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0+int(y), y0-int(x), r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0-int(y), y0+int(x), r8, g8, b8, a8)
|
||||
DrawPointIfInBounds(img, bounds, x0-int(y), y0-int(x), r8, g8, b8, a8)
|
||||
|
||||
if d < 0 {
|
||||
d += 4*x + 6
|
||||
|
||||
Reference in New Issue
Block a user