Skip to content

Commit

Permalink
ebitenutil: add DrawCircle (hajimehoshi#2175)
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Piwowarczyk authored Jul 3, 2022
1 parent c31cc4e commit a249296
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ebitenutil/shapes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"math"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/vector"
)

var (
Expand Down Expand Up @@ -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)
}

0 comments on commit a249296

Please sign in to comment.