25 lines
544 B
Go
25 lines
544 B
Go
package imageutils
|
|
|
|
import (
|
|
"image"
|
|
"image/color"
|
|
)
|
|
|
|
// go.dev/blog/image-draw#drawing-through-a-mask
|
|
type Circle struct {
|
|
image.Point
|
|
R int
|
|
}
|
|
|
|
func (c Circle) ColorModel() color.Model { return color.AlphaModel }
|
|
func (c Circle) Bounds() image.Rectangle {
|
|
return image.Rect(c.Point.X-c.R, c.Point.Y-c.R, c.Point.X+c.R, c.Point.Y+c.R)
|
|
}
|
|
func (c Circle) At(x, y int) color.Color {
|
|
xx, yy, rr := float64(x-c.Point.X)+0.5, float64(y-c.Point.Y)+0.5, float64(c.R)
|
|
if xx*xx+yy*yy < rr*rr {
|
|
return color.Opaque
|
|
}
|
|
return color.Transparent
|
|
}
|