random circles example

This commit is contained in:
2026-04-04 16:57:10 +03:00
parent 3880b353c1
commit 824a4ede47
13 changed files with 308 additions and 1 deletions

24
circle.go Normal file
View File

@@ -0,0 +1,24 @@
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
}