diff --git a/ebitenutil/shapes.go b/ebitenutil/shapes.go index 12ca75e8f..3bccfe379 100644 --- a/ebitenutil/shapes.go +++ b/ebitenutil/shapes.go @@ -20,6 +20,7 @@ import ( "math" "github.com/hajimehoshi/ebiten/v2" + "github.com/hajimehoshi/ebiten/v2/vector" ) var ( @@ -59,3 +60,24 @@ func DrawRect(dst *ebiten.Image, x, y, width, height float64, clr color.Color) { // Linear filtering would make edges blurred. dst.DrawImage(emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image), op) } + +// DrawCircle draws a circle on given destination dst. +// +// DrawCircle is intended to be used mainly for debugging or prototyping puropose. +func DrawCircle(dst *ebiten.Image, cx, cy, r float64, clr color.Color) { + var path vector.Path + rd, g, b, a := clr.RGBA() + + path.Arc(float32(cx), float32(cy), float32(r), 0, 2*math.Pi, vector.Clockwise) + + verticles, indices := path.AppendVerticesAndIndicesForFilling(nil, nil) + for i := range verticles { + verticles[i].SrcX = 1 + verticles[i].SrcY = 1 + verticles[i].ColorR = float32(rd) / 0xffff + verticles[i].ColorG = float32(g) / 0xffff + verticles[i].ColorB = float32(b) / 0xffff + verticles[i].ColorA = float32(a) / 0xffff + } + dst.DrawTriangles(verticles, indices, emptySubImage, nil) +}